2017-09-29 4:29 GMT+02:00 Lorenzo Caminiti via Boost
On Thu, Sep 28, 2017 at 4:05 PM, Niall Douglas via Boost
wrote: Why... what changed in C++1z that makes the above compile? How can I prevent copying x outside its friend function f in C++1z?
C++ 17 guarantees copy elision in the strong sense.
Note it still can't be copied, but it can be initialised now. So disable non-friend construction to fix.
I see. However, making the constructor private still does not make the compilation fail. The following code compiles fine on clang++ -std=c++1z ...
struct x { private: x() {} x(x const&) {} x& operator=(x const&) { return *this; }
friend x f(); };
x f() { return x(); }
int main() { auto xx = f(); return 0; }
Is there any way to make that `auto xx = f()` in main fail at compile time in C++1z?
But why do you want this program to fail to compile? Regards, &rzej;