I expect the following code to result in an error, regardless of whether the copy is optimized or not:
struct A {
A() {}
A(const A&) = delete;
};
int main() {
A a = A();
}
Indeed, this is what happens in C++14 and earlier:
main2.cpp:7:7: error: call to deleted constructor of 'A'
A a = A();
^ ~~~
main2.cpp:3:5: note: 'A' has been explicitly marked deleted here
A(const A&) = delete;
^
But in C++17, this peacefully compiles (with both gcc and clang). What change in C++17 is responsible for this, and how can I now enforce the previous semantics?