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]