This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor
- From: "luto at mit dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 04 May 2012 18:27:05 +0000
- Subject: [Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53234
Bug #: 53234
Summary: [c++0x] unfriendly error message for missing move
constructor
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: luto@mit.edu
This code is correctly rejected by gcc 4.7 and up (4.6 incorrectly accepted
it). The error message confused me for a while, though.
struct move_only
{
move_only() = default;
move_only(move_only&&) = default;
move_only &operator = (move_only&&) = default;
};
struct is_it_moveable
{
//is_it_moveable() = default;
//is_it_moveable(is_it_moveable &&) = default;
~is_it_moveable();
move_only mo;
};
int main()
{
is_it_moveable j;
is_it_moveable k = (is_it_moveable&&)j;
}
A recent trunk build says:
move.cc: In function âint main()â:
move.cc:20:40: error: use of deleted function
âis_it_moveable::is_it_moveable(const is_it_moveable&)â
is_it_moveable k = (is_it_moveable&&)j;
^
move.cc:8:8: note: âis_it_moveable::is_it_moveable(const is_it_moveable&)â is
implicitly deleted because the default definition would be ill-formed:
struct is_it_moveable
^
move.cc:8:8: error: use of deleted function âconstexpr
move_only::move_only(const move_only&)â
struct is_it_moveable
^
move.cc:1:8: note: âconstexpr move_only::move_only(const move_only&)â is
implicitly declared as deleted because âmove_onlyâ declares a move constructor
or move assignment operator
struct move_only
^
This is, according to the standard, exactly correct. [class.copy] paragraph 9
says "If the definition of a class X does not explicitly declare a move
constructor, one will be implicitly declared as defaulted if and only if
[condition that does not apply here]." The note says "When the move
constructor is not implicitly declared or explicitly supplied, expressions that
otherwise would have invoked the move constructor may instead invoke a copy
constructor."
I think the error message could be improved to help C++11 newbies like myself,
though. An extra line like:
note: is_it_moveable has no move constructor because it has a user-declared
destructor
would be quite friendly. I spent a while staring at the error, thinking "of
course the copy constructor would be ill-formed. That's way I called the
*move* constructor, you dummy!"
(FWIW, this change is missing from the 4.7 release notes. I think it, or
something related, breaks boost 1.47's shared_ptr quite thoroughly.)