From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13319 invoked by alias); 1 Nov 2010 00:15:50 -0000 Received: (qmail 13304 invoked by uid 22791); 1 Nov 2010 00:15:47 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 01 Nov 2010 00:15:43 +0000 From: "redi at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Mon, 01 Nov 2010 00:15:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-11/txt/msg00000.txt.bz2 Message-ID: <20101101001500.evwpDGhktfvEdQdkqIHkSGZ7HQFjBVEUrnKxDtyxaG0@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46246 --- Comment #7 from Jonathan Wakely 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 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