This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[c++0x] inconsistent behaviour with defaulted move constructor
- From: Roman Kononov <roman at binarylife dot net>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 30 Nov 2010 16:51:30 -0600
- Subject: [c++0x] inconsistent behaviour with defaulted move constructor
The two programs below differ by the location of =default applied to
the move constructor. In the first program, it is defaulted inside
the class during declaration. In the second program, it is defaulted
outside the class in the definition.
The first program does not compile. The second does compile. Is it a
bug or am I misuse gcc?
Thanks.
$ cat test1.cc
struct U {
U();
U(U const&);
};
struct X {
U const u;
X()=default;
X(X&&)=default;
};
X test() {
X a={};
return a;
}
$ g++ -c -std=c++0x test1.cc
test1.cc: In function 'X test()':
test1.cc:14:10: error: use of deleted function 'X::X(X&&)'
test1.cc:9:3: error: 'X::X(X&&)' is implicitly deleted because the default definition would be ill-formed:
test1.cc:9:3: error: non-static data member 'X::u' does not have a move constructor or trivial copy constructor
$ cat test2.cc
struct U {
U();
U(U const&);
};
struct X {
U const u;
X()=default;
X(X&&);
};
X::X(X&&)=default;
X test() {
X a={};
return a;
}
$ g++ -c -std=c++0x test2.cc && echo $?
0