I'd like to hear comments about my observations regarding the example below in the approved CWG paper "Guaranteed copy elision through simplified valu

  • Thread starter Thread starter Belloc
  • Start date Start date
B

Belloc

Guest
The document "Guaranteed copy elision" can be found here.

Definitions and declarations given in the section "What would mandatory copy elision look like?" of the alluded document.

struct NonMoveable {
NonMoveable(int);
NonMoveable(NonMoveable&) = delete;
NonMoveable(NonMoveable&&) = delete;
void NonMoveable(const NonMoveable&) = delete;
std::array<int, 1024> arr;
};

NonMoveable make() {
return NonMoveable(42);
}

See below the snippet that I decided to investigate a little further in the section "Implications of refined value categories" in the alluded document.

NonMoveable x = {5}; // ok today
NonMoveable x = 5; // equivalent to NonMoveable x = NonMoveable(5),
// ill-formed today (creates a temporary but can't move it),
// ok under this proposal (does not create a temporary object)

My observations are in the comments here. The code shows the error messages for C++14. But you can easily change that to C++17 in the box Compiler options. It took me a few hours analyzing this and I just want to make sure I'm not missing anything. Thank you.

P.S.: I had to change the last initialization above to avoid the silly error that variable x was already defined. Thus I changed that initialization to

NonMoveable y = 3;

Continue reading...
 
Back
Top