public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54319] New: Assignment to rvalue
@ 2012-08-19  3:37 aschepler at gmail dot com
  2012-08-19  7:30 ` [Bug c++/54319] " daniel.kruegler at googlemail dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: aschepler at gmail dot com @ 2012-08-19  3:37 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: aschepler@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)


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-03-18 13:32 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-19  3:37 [Bug c++/54319] New: Assignment to rvalue aschepler at gmail dot com
2012-08-19  7:30 ` [Bug c++/54319] " daniel.kruegler at googlemail dot com
2012-08-19 11:55 ` paolo.carlini at oracle dot com
2012-08-19 12:13 ` daniel.kruegler at googlemail dot com
2012-08-19 12:43 ` paolo.carlini at oracle dot com
2021-07-28  0:32 ` [Bug c++/54319] empty class causes error while non-empty does not pinskia at gcc dot gnu.org
2021-07-28  1:00 ` [Bug c++/54319] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2021-07-28  1:08 ` pinskia at gcc dot gnu.org
2021-07-28  1:12 ` pinskia at gcc dot gnu.org
2021-07-28  1:23 ` pinskia at gcc dot gnu.org
2021-07-28  2:30 ` pinskia at gcc dot gnu.org
2021-07-28  2:46 ` pinskia at gcc dot gnu.org
2021-07-28  2:49 ` pinskia at gcc dot gnu.org
2021-07-28  2:50 ` pinskia at gcc dot gnu.org
2022-01-17 15:21 ` rguenth at gcc dot gnu.org
2022-03-18 13:32 ` ppalka at gcc dot gnu.org

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).