public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "luto at mit dot edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53234] New: [c++0x] unfriendly error message for missing move constructor Date: Fri, 04 May 2012 18:27:00 -0000 [thread overview] Message-ID: <bug-53234-4@http.gcc.gnu.org/bugzilla/> (raw) 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.)
next reply other threads:[~2012-05-04 18:27 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-05-04 18:27 luto at mit dot edu [this message] 2012-05-04 19:07 ` [Bug c++/53234] " redi at gcc dot gnu.org 2020-03-20 4:25 ` luto at kernel dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-53234-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).