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: unassig...@gcc.gnu.org
        ReportedBy: l...@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.)

Reply via email to