Created attachment 22208 [details] test case that fails to compile The attached test case causes a compiler error, GCC seems to need the unavailable move constructor even if a
Created attachment 22209 [details] test case that shows that the move constructor is not actually used
The secondo attachment compiles, but the move constructor seems not really used. The output is: default bar foo called Moreover i was expecting a call to the copy constructor but that was elided, is this an optimization or something mandated by the standard?
Let's add Jason in CC..
Copy elision is an optimisation allowed by the standard, but not mandated. -fno-elide-constructors to disable it, then you should see the move constructor called for the second test case. The relevant constructor must be accessible and callable even if it is elided.
Makes sense, of course (I'm not used to private or protected deleted members). Thus looks like this can closed as invalid?
Please consider the first test case before declaring this bug invalid. I think should be legal to delete the move construtor and still being able to pass temporaries by copy.
No, a deleted function can still be selected by overload resolution. Defining a move constructor as deleted does not have the semantics you want. In the current draft, n3126, a user-declared copy constructor suppresses the implicit declaration of a move constructor. So all you need to do to make a class copyable but not movable is declare the copy constructor. Don't declare a move constructor, definitely don't define it as deleted. $ cat foo.cpp #include <iostream> using namespace std; class Bar { public: Bar() { cout << "default bar" << endl; } Bar(const Bar& r) { cout << "copy bar" << endl; } }; void foo(Bar p) { cout << "foo called" << endl; } int main() { foo(Bar()); return 0; } $ g++ -std=c++0x foo.cpp -fno-elide-constructors $ ./a.out default bar copy bar foo called
Jonathan is correct.