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

Annex C (informative) Compatibility [diff]

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

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

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

Change: The class name can no longer be used parenthesized immediately after an explicit decl-specifierin a constructor 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&); explicit (operator int)(); explicit(true) (S)(int); }; — _end example_]

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

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: template<class T> struct A { A<T>(); A(int); ~A<T>(); }; — _end example_]

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; derived d;return d; } 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; } — _end example_]