[cfe-dev] Move constructor forces copy assignment to be implicitly defaulted?
Suman Kar
skarpio at gmail.com
Fri May 25 01:44:36 PDT 2012
Hello,
The following piece of code:
copytest.cpp
--
struct movable {
movable() {}
movable(movable const&) {}
movable(movable &&) {}
};
void copy_assignment(movable && t) {
movable m;
m = t;
}
int main() {}
--
with clang (version details):
--
clang version 3.2 (trunk 157115) (llvm/trunk 157155)
Target: i686-pc-mingw32
Thread model: posix
--
throws an error (and some helpful diagnostics). The error message is:
--
copytest.cpp:63:4: error: overload resolution selected implicitly-deleted copy
assignment operator
m = t;
^
copytest.cpp:58:2: note: copy assignment operator is implicitly deleted because
'movable' has a user-declared move constructor
movable(movable &&) {}
^
1 error generated.
--
My reading of the relevant section of the standard (I only have N3126
handy, so I may be mistaken): ยง12.8/20:
If the class definition does not explicitly declare a
copy assignment operator and there is no user-declared
move assignment operator, a copy assignment operator
is implicitly declared as defaulted (8.4).
tells me that an implicitly *defaulted* copy assignment operator
should've been generated and used instead.
I am using this clang with gcc 4.6. gcc 4.6 (standalone) seems to
accept this (with -std=c++0x, -Wall and a few other warning parameters
turned on).
Can someone help me understand this behavior?
Regards,
Suman Kar
More information about the cfe-dev
mailing list