public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used Date: Mon, 01 Nov 2010 00:15:00 -0000 [thread overview] Message-ID: <20101101001500.evwpDGhktfvEdQdkqIHkSGZ7HQFjBVEUrnKxDtyxaG0@z> (raw) In-Reply-To: <bug-46246-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46246 --- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 00:15:33 UTC --- No, a deleted function can still be selected by overload resolution. Defining a move constructor as deleted does not have the semantics you want. In the current draft, n3126, a user-declared copy constructor suppresses the implicit declaration of a move constructor. So all you need to do to make a class copyable but not movable is declare the copy constructor. Don't declare a move constructor, definitely don't define it as deleted. $ cat foo.cpp #include <iostream> using namespace std; class Bar { public: Bar() { cout << "default bar" << endl; } Bar(const Bar& r) { cout << "copy bar" << endl; } }; void foo(Bar p) { cout << "foo called" << endl; } int main() { foo(Bar()); return 0; } $ g++ -std=c++0x foo.cpp -fno-elide-constructors $ ./a.out default bar copy bar foo called
next prev parent reply other threads:[~2010-11-01 0:15 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-10-30 16:27 [Bug c++/46246] New: " a.pignotti at sssup dot it 2010-10-30 16:29 ` [Bug c++/46246] " a.pignotti at sssup dot it 2010-10-30 16:31 ` a.pignotti at sssup dot it 2010-10-31 10:01 ` paolo.carlini at oracle dot com 2010-10-31 12:05 ` redi at gcc dot gnu.org 2010-10-31 13:28 ` paolo.carlini at oracle dot com 2010-10-31 15:10 ` a.pignotti at sssup dot it 2010-11-01 0:15 ` redi at gcc dot gnu.org [this message] 2010-11-01 14:17 ` jason at gcc dot gnu.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=20101101001500.evwpDGhktfvEdQdkqIHkSGZ7HQFjBVEUrnKxDtyxaG0@z \ --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).