From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9970 invoked by alias); 19 Aug 2012 03:37:50 -0000 Received: (qmail 9913 invoked by uid 22791); 19 Aug 2012 03:37:49 -0000 X-SWARE-Spam-Status: No, hits=-3.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_CX,TW_DC,TW_GX 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; Sun, 19 Aug 2012 03:37:35 +0000 From: "aschepler at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/54319] New: Assignment to rvalue Date: Sun, 19 Aug 2012 03:37: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: normal X-Bugzilla-Who: aschepler at gmail 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" Content-Transfer-Encoding: quoted-printable 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-08/txt/msg01262.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D54319 Bug #: 54319 Summary: Assignment to rvalue Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: aschepler@gmail.com g++ seems to think "A =3D B" is a prvalue if expression A is a prvalue of a= class type with no members. Example code: ----- template struct is_same { static const bool value =3D false; }; template struct is_same { static const bool value =3D true; }; struct X {}; struct Y { int m; }; void f() { static_assert(is_same::value, "Y assignment does not result in lvalue"); static_assert(is_same::value, "X assignment does not result in lvalue"); } ----- g++ -std=3Dc++0x -c rval_assign.cpp rval_assign3.cpp: In function =E2=80=98void f()=E2=80=99: rval_assign3.cpp:18:3: error: static assertion failed: X assignment does not result in lvalue ----- The difference in behavior between X and Y is surprising, since both are PO= D. Although assigning to a prvalue is questionable practice, it's allowed in t= his case and the assignment expression is an lvalue because of 12.8 paragraph 2= 2: The implicitly-declared move assignment operator for a class X will have = the form X& X::operator=3D(X&&); ----- g++ -v Using built-in specs. COLLECT_GCC=3Dg++ COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/i486-linux-gnu/4.7/lto-wrapper Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Debian 4.7.1-2' --with-bugurl=3Dfile:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=3Dc,c++,go,fortran,objc,obj-c++ --prefix=3D/usr --program-suffix=3D-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --with-gxx-include-dir=3D/usr/include/c++/4.7 --libdir=3D/usr/lib --enable-nls --with-sysroot=3D/ --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --enable-gnu-unique-= object --enable-plugin --enable-objc-gc --enable-targets=3Dall --with-arch-32=3Di5= 86 --with-tune=3Dgeneric --enable-checking=3Drelease --build=3Di486-linux-gnu --host=3Di486-linux-gnu --target=3Di486-linux-gnu Thread model: posix gcc version 4.7.1 (Debian 4.7.1-2)