This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 1 Nov 2010 00:15:41 +0000
- Subject: [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
- Auto-submitted: auto-generated
- References: <bug-46246-4@http.gcc.gnu.org/bugzilla/>
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