Files
2025-10-25 03:02:53 +03:00

3.8 KiB

[diff.cpp17.class]

Annex C (informative) Compatibility [diff]

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

C.3.6 [class]: classes [diff.cpp17.class]

1

#

Affected subclauses: [class.ctor] and [class.conv.fct]

Change: The class name can no longer be used parenthesized immediately after an explicit decl-specifier in a constructor declaration.

The conversion-function-id can no longer be used parenthesized immediately after an explicit decl-specifier in a conversion function declaration.

Rationale: Necessary for new functionality.

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

[Example 1: struct S {explicit (S)(const S&); // ill-formed; previously well-formedexplicit (operator int)(); // ill-formed; previously well-formedexplicit(true) (S)(int); // OK}; — end example]

2

#

Affected subclauses: [class.ctor] and [class.dtor]

Change: A simple-template-id is no longer valid as the declarator-id of a constructor or destructor.

Rationale: Remove potentially error-prone option for redundancy.

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

[Example 2: templatestruct A { A(); // error: simple-template-id not allowed for constructor A(int); // OK, injected-class-name used~A(); // error: simple-template-id not allowed for destructor}; — end example]

3

#

Affected subclause: [class.copy.elision]

Change: A function returning an implicitly movable entity may invoke a constructor taking an rvalue reference to a type different from that of the returned expression.

Function and catch-clause parameters can be thrown using move constructors.

Rationale: Side effect of making it easier to write more efficient code that takes advantage of moves.

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

[Example 3: struct base { base(); base(base const &);private: base(base &&);};

struct derived : base {};

base f(base b) {throw b; // error: base(base &&) is private derived d; return d; // error: base(base &&) is private}struct S { S(const char *s) : m(s) { } S(const S&) = default; S(S&& other) : m(other.m) { other.m = nullptr; }const char * m;};

S consume(S&& s) { return s; }void g() { S s("text"); consume(static_cast<S&&>(s)); char c = *s.m; // undefined behavior; previously ok} — end example]