[diff.cpp17.dcl.dcl] (original) (raw)

Annex C (informative) Compatibility [diff]

C.3 C++ and ISO C++ 2017 [diff.cpp17]

C.3.5 [dcl]: declarations [diff.cpp17.dcl.dcl]

Affected subclause: [dcl.typedef]

Change: Unnamed classes with a typedef name for linkage purposes can contain only C-compatible constructs.

Rationale: Necessary for implementability.

Effect on original feature: Valid C++ 2017 code may be ill-formed in this revision of C++.

[Example 1: typedef struct { void f() {} } S; — _end example_]

Affected subclause: [dcl.fct.default]

Change: A function cannot have different default arguments in different translation units.

Rationale: Required for modules support.

Effect on original feature: Valid C++ 2017 code may be ill-formed in this revision of C++, with no diagnostic required.

[Example 2: int f(int a = 42);int g() { return f(); } int f(int a = 76) { return a; } int g();int main() { return g(); } — _end example_]

Affected subclause: [dcl.init.aggr]

Change: A class that has user-declared constructors is never an aggregate.

Rationale: Remove potentially error-prone aggregate initialization which may apply notwithstanding the declared constructors of a class.

Effect on original feature: Valid C++ 2017 code that aggregate-initializes a type with a user-declared constructor may be ill-formed or have different semantics in this revision of C++.

[Example 3: struct A { A() = delete;};struct B { B() = default;int i = 0;};struct C { C(C&&) = default;int a, b;}; A a{}; B b = {1}; auto* c = new C{2, 3}; struct Y;struct X { operator Y();};struct Y { Y(const Y&) = default; X x;}; Y y{X{}}; — _end example_]

Affected subclause: [dcl.init.list]

Change: Boolean conversion from a pointer or pointer-to-member type is now a narrowing conversion.

Rationale: Catches bugs.

Effect on original feature: Valid C++ 2017 code may fail to compile in this revision of C++.

[Example 4: bool y[] = { "bc" }; — _end example_]