public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66501] New: Default move assignment does not move array members
@ 2015-06-11  6:48 john.lindgren at aol dot com
  2015-06-11  8:07 ` [Bug c++/66501] [4.9/5/6 Regression] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: john.lindgren at aol dot com @ 2015-06-11  6:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66501

            Bug ID: 66501
           Summary: Default move assignment does not move array members
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: john.lindgren at aol dot com
  Target Milestone: ---

In the following code, main() should return 0 (and did with GCC 4.8.2).  With
GCC 5.1.0, main() instead returns 2.  It seems that the compiler-generated
Container::operator=(Container&&) does not call Object::operator=(Object&&) as
it ought.  So the line "container=Container()" line does not subtract 2 from
total_size as would be expected.

int total_size;

struct Object
{
    int size = 0;

    Object () = default;

    ~Object () {
        total_size -= size;
    }

    Object (const Object &) = delete;
    Object & operator= (const Object &) = delete;

    Object (Object && b) {
        size = b.size;
        b.size = 0;
    }

    Object & operator= (Object && b) {
        if (this != & b) {
            total_size -= size;
            size = b.size;
            b.size = 0;
        }
        return * this;
    }

    void grow () {
        size ++;
        total_size ++;
    }
};

struct Container {
    Object objects[2];
};

int main (void)
{
    Container container;

    // grow some objects in the container
    for (auto & object : container.objects)
        object.grow ();

    // now empty it
    container = Container ();

    return total_size;
}

gcc -v gives:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc-multilib/src/gcc-5-20150519/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --enable-multilib --disable-werror
--enable-checking=release --with-default-libstdcxx-abi=c++98
Thread model: posix
gcc version 5.1.0 (GCC)


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

end of thread, other threads:[~2015-06-24 20:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11  6:48 [Bug c++/66501] New: Default move assignment does not move array members john.lindgren at aol dot com
2015-06-11  8:07 ` [Bug c++/66501] [4.9/5/6 Regression] " redi at gcc dot gnu.org
2015-06-12 17:01 ` daniel.kruegler at googlemail dot com
2015-06-23 14:09 ` jason at gcc dot gnu.org
2015-06-24 15:40 ` jason at gcc dot gnu.org
2015-06-24 15:41 ` jason at gcc dot gnu.org
2015-06-24 15:42 ` jason at gcc dot gnu.org
2015-06-24 20:01 ` jason 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).