Possible Duplicate:
Why do C++11-deleted functions participate in overload resolution?
I have two questions about the following C++11 code:
#include <iostream>
using namespace std;
struct A {
A() { cout << "Default c-tor" << endl; }
A(const A&) { cout << "Copy c-tor" << endl; }
A(A&&) = delete;
};
A f()
{
A a;
return a;
}
int main()
{
A b = f();
return 0;
}
I get the following compile errors with gcc and clang
gcc-4.7.2 (g++ --std=c++11 main.cpp):
main.cpp: In function ‘A f()’:
main.cpp:16:9: error: use of deleted function ‘A::A(A&&)’
main.cpp:8:2: error: declared here
main.cpp: In function ‘int main()’:
main.cpp:21:10: error: use of deleted function ‘A::A(A&&)’
main.cpp:8:2: error: declared here
clang-3.0 (clang++ --std=c++11 main.cpp):
main.cpp:19:4: error: call to deleted constructor of 'A'
A b = f();
^ ~~~
main.cpp:8:2: note: function has been explicitly marked deleted here
A(A&&) = delete;
^
1 error generated.
- Shouldn't the compiler use the copy constructor if the move constructor is explicitly deleted?
- Does anyone know any use for "non-movable" types?
Thanks in advance.