http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54319
Bug #: 54319 Summary: Assignment to rvalue Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: aschep...@gmail.com g++ seems to think "A = B" is a prvalue if expression A is a prvalue of a class type with no members. Example code: ----- template<typename T, typename U> struct is_same { static const bool value = false; }; template<typename T> struct is_same<T,T> { static const bool value = true; }; struct X {}; struct Y { int m; }; void f() { static_assert(is_same<decltype((Y{} = Y{})), Y&>::value, "Y assignment does not result in lvalue"); static_assert(is_same<decltype((X{} = X{})), X&>::value, "X assignment does not result in lvalue"); } ----- g++ -std=c++0x -c rval_assign.cpp rval_assign3.cpp: In function ‘void f()’: 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 POD. Although assigning to a prvalue is questionable practice, it's allowed in this case and the assignment expression is an lvalue because of 12.8 paragraph 22: The implicitly-declared move assignment operator for a class X will have the form X& X::operator=(X&&); ----- g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.7/lto-wrapper Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.1-2' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.7.1 (Debian 4.7.1-2)