From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14989 invoked by alias); 7 Apr 2012 16:35:44 -0000 Received: (qmail 14977 invoked by uid 22791); 7 Apr 2012 16:35:41 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Sat, 07 Apr 2012 16:35:27 +0000 From: "dieter.lucking at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52901] New: invalid rvalue reference Date: Sat, 07 Apr 2012 16:35:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: dieter.lucking at googlemail dot com 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: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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: 2012-04/txt/msg00478.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52901 Bug #: 52901 Summary: invalid rvalue reference Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: dieter.lucking@googlemail.com Created attachment 27111 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27111 code A different result - just reordering the cout output. #include using namespace std; struct X { int value; X() { cout << "default construction" << std::endl; value = 0; } X(const X& other) { cout << "copy construction" << std::endl; value = 1; } X(X&& other) { cout << "move construction" << std::endl; value = 2; } X& operator = (const X& other) { cout << "assignment" << std::endl; value = 3; return *this; } }; X&& f() { X x; return std::move(x); } int main() { cout << "Hello References [1]" << std::endl; X x0 = f(); cout << "x0: " << x0.value << std::endl; X&& x1 = f(); cout << "No copy construction or assignment expected" << std::endl; cout << "x1: " << x1.value << std::endl; cout << "Hello References [2]" << std::endl; X y0 = f(); cout << "y0: " << y0.value << std::endl; X&& y1 = f(); cout << "y1: " << y1.value << std::endl; cout << "No copy construction or assignment expected" << std::endl; return 0; } // Seems g++ 4.6.1 is buggy: // Hello References [1] // default construction // move construction // x0: 2 // default construction // No copy construction or assignment expected // x1: 6295648 // Hello References [2] // default construction // move construction // y0: 2 // default construction // y1: 0 // No copy construction or assignment expected