http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46246

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 
00:15:33 UTC ---
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

Reply via email to