[Bug c++/68949] New: [5.? Regression] Implicit initialization of array member silently miscompiling.

woutershep at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Dec 16 22:13:00 GMT 2015


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

            Bug ID: 68949
           Summary: [5.? Regression] Implicit initialization of array
                    member silently miscompiling.
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: woutershep at gmail dot com
  Target Milestone: ---

Created attachment 37056
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37056&action=edit
ii

Hello, i believe that i have found a bug in gcc. This is my first time
submitting a bug to this project so if i'm missing something important please
let me know so i can provide it. I've tried to follow the guidelines best i
could.

More specifically, i think there is a bug in the way it handles the implicit
default initialization of an array member when that member has a constexpr
constructor and a non-inline move constructor that delegates.

I can imagine that doesn't really paint a clear picture so ill just let the
code do the talking instead:

"""
// % $CXX -std=c++11 -Wall -Wextra -o zero zero.cc && ./zero; echo $?
//
// expected return
// return of g++ 4.9.2
// return of clang++ 3.7.0
// 0
//
// return of g++ 5.2.0
// return of g++ 5.3.0
// 1

struct Sub {
    int i;

    constexpr Sub() : i(-1) {} // remove constexpr and it works as expected
    Sub(Sub&& rhs); // remove this constructor and it works as epxected.
};

// v-- move this inline and it works as expected
// v-- remove ': Sub()' and it works as expected
Sub::Sub(Sub&& rhs) : Sub() { int tmp = i; i = rhs.i; rhs.i = tmp; }

struct Class {
    // v-- remove '[1]' and it works as expected
    // v-- add '= {}' and it works as expected
    Sub s[1];

    // v-- add ': s{}' and it works as expected
    // v-- removing this constructor makes it work as expected
    Class() {}
};

int main() {
    Class c;
    return c.s[0].i != -1;
}
"""

Instead of the expected '-1', 'i' is actually '0' on 5.2 and 5.3 causing it to
return 1 on those.

Ive attached the .ii that this file produced. And for completion here is the -v
output of the gcc's i had at my disposal (the gcc-5.2 behavior was given by
someone else):

% x86_64-pc-linux-gnu-gcc-5.1 -v
Using built-in specs.
COLLECT_GCC=x86_64-pc-linux-gnu-gcc-5.1
COLLECT_LTO_WRAPPER=/usr/x86_64-pc-linux-gnu/libexec/gcc/x86_64-pc-linux-gnu/5.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/paludis/build/sys-devel-gcc-5.3.0/work/gcc-5.3.0/configure
--cache-file=config.cache --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
--prefix=/usr/x86_64-pc-linux-gnu --datarootdir=/usr/share --localstatedir=/var
--sysconfdir=/etc --disable-dependency-tracking --enable-fast-install
--enable-serial-configure --disable-bootstrap --disable-decimal-float
--disable-install-libiberty --disable-libada --disable-libatomic
--disable-libcilkrts --disable-libffi --disable-libgfortran --disable-libgo
--disable-libgomp --disable-libitm --disable-libjava --disable-libmpx
--disable-libobjc --disable-liboffloadmic --disable-libquadmath
--disable-libsanitizer --disable-libssp --disable-libstdcxx
--disable-libstdc++-v3 --disable-libvtv --disable-vtable-verify
--disable-multilib --disable-nls --disable-shared --enable-lto --disable-plugin
--enable-threads --enable-languages=c,c++,fortran,objc,obj-c++ --with-sysroot=
--with-gxx-include-dir=/usr/x86_64-pc-linux-gnu/include/c++/5.3.0 --with-isl
--program-transform='s,$,-5.1,' --with-lib-path=/usr/x86_64-pc-linux-gnu/lib
--with-as=/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-as
--with-ld=/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ld
--with-system-zlib --with-glibc-version=2.11 --enable-linker-build-id
--with-multilib-list=
Thread model: posix
gcc version 5.3.0 (GCC)

% x86_64-pc-linux-gnu-gcc-4.9 -v
Using built-in specs.
COLLECT_GCC=x86_64-pc-linux-gnu-gcc-4.9
COLLECT_LTO_WRAPPER=/usr/x86_64-pc-linux-gnu/libexec/gcc/x86_64-pc-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/paludis/build/sys-devel-gcc-4.9.2-r11/work/gcc-4.9.2/configure
--cache-file=config.cache --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
--prefix=/usr/x86_64-pc-linux-gnu --datarootdir=/usr/share --localstatedir=/var
--sysconfdir=/etc --disable-dependency-tracking --enable-fast-install
--enable-serial-configure --disable-bootstrap --disable-decimal-float
--disable-install-libiberty --disable-libada --disable-libatomic
--disable-libcilkrts --disable-libffi --disable-libgfortran --disable-libgo
--disable-libgomp --disable-libitm --disable-libjava --disable-libobjc
--disable-libquadmath --disable-libsanitizer --disable-libssp
--disable-libstdcxx --disable-libstdc++-v3 --disable-libvtv
--disable-vtable-verify --disable-multilib --disable-nls --disable-shared
--enable-lto --disable-plugin --enable-threads
--enable-languages=c,c++,fortran,objc,obj-c++ --with-sysroot=
--with-gxx-include-dir=/usr/x86_64-pc-linux-gnu/include/c++/4.9.2
--without-cloog --program-transform='s,$,-4.9,'
--with-lib-path=/usr/x86_64-pc-linux-gnu/lib
--with-as=/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-as
--with-ld=/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ld
--with-system-zlib --with-glibc-version=2.11 --enable-linker-build-id
--with-multilib-list=
Thread model: posix
gcc version 4.9.2 (GCC)


More information about the Gcc-bugs mailing list