Bug 57998 - Unhelpful error message when a class has no move constructor
Summary: Unhelpful error message when a class has no move constructor
Status: RESOLVED DUPLICATE of bug 53234
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-27 01:40 UTC by Andy Lutomirski
Modified: 2020-03-20 04:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Lutomirski 2013-07-27 01:40:51 UTC
When trying and failing to move an object because the move constructor is deleted, the error message tells you so.  When there is no move constructor at all, however, the error message is unhelpful.  For example, this:

#include <utility>

struct move_only
{
  move_only() = default;
  move_only(move_only&&) = default;
  move_only &operator = (move_only&&) = default;
};

struct broken : move_only
{
  move_only mo;
  ~broken() {}
};

void test()
{
  broken a;
  broken b(std::move(a));
}

is correctly rejected with this error:

move_base.cc: In function ‘void test()’:
move_base.cc:19:24: error: use of deleted function ‘broken::broken(const broken&)’
   broken b(std::move(a));
                        ^
move_base.cc:10:8: note: ‘broken::broken(const broken&)’ is implicitly deleted because the default definition would be ill-formed:
 struct broken : move_only
        ^
move_base.cc:10:8: error: use of deleted function ‘constexpr move_only::move_only(const move_only&)’
move_base.cc:3: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
        ^
move_base.cc:10:8: error: use of deleted function ‘constexpr move_only::move_only(const move_only&)’
 struct broken : move_only
        ^

It would be much more helpful if there was another line saying something like "broken::broken(broken&&) is suppressed because broken has a user-defined destructor".
Comment 1 S. Davis Herring 2020-03-19 23:50:03 UTC
This is a duplicate of (your own!) #53234.
Comment 2 Andy Lutomirski 2020-03-20 04:25:58 UTC
Indeed.  That's slightly embarrassing.  I admit that after more than six years I don't remember how I made this mistake :)

*** This bug has been marked as a duplicate of bug 53234 ***