public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor
@ 2012-05-04 18:27 luto at mit dot edu
  2012-05-04 19:07 ` [Bug c++/53234] " redi at gcc dot gnu.org
  2020-03-20  4:25 ` luto at kernel dot org
  0 siblings, 2 replies; 3+ messages in thread
From: luto at mit dot edu @ 2012-05-04 18:27 UTC (permalink / raw)
  To: gcc-bugs

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.)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/53234] [c++0x] unfriendly error message for missing move constructor
  2012-05-04 18:27 [Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor luto at mit dot edu
@ 2012-05-04 19:07 ` redi at gcc dot gnu.org
  2020-03-20  4:25 ` luto at kernel dot org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-04 19:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53234

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-05-04
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-04 19:06:51 UTC ---
Yes, your suggested note would be helpful.

(In reply to comment #0)
> (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.)

Older versions of Boost rarely work with newer versions of G++, especially in
C++11 mode, because noone tests Boost svn against GCC svn any more.  Even if
the GCC 4.7 release notes had mentioned the change it wouldn't have made any
difference, I think Boost 1.47 had already been released when the change was
made and it would be too late to fix it.

Maybe we could add something to http://gcc.gnu.org/gcc-4.7/porting_to.html
about the change.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/53234] [c++0x] unfriendly error message for missing move constructor
  2012-05-04 18:27 [Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor luto at mit dot edu
  2012-05-04 19:07 ` [Bug c++/53234] " redi at gcc dot gnu.org
@ 2020-03-20  4:25 ` luto at kernel dot org
  1 sibling, 0 replies; 3+ messages in thread
From: luto at kernel dot org @ 2020-03-20  4:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53234

--- Comment #2 from Andy Lutomirski <luto at kernel dot org> ---
*** Bug 57998 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-20  4:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-04 18:27 [Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor luto at mit dot edu
2012-05-04 19:07 ` [Bug c++/53234] " redi at gcc dot gnu.org
2020-03-20  4:25 ` luto at kernel dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).