The C++ program below defines structures that each contain a 1-byte char field and inherit linearly from various numbers of empty bases (one empty base for X, two for Y, three for Z). By my reading of the standard, all of these should be considered to be standard-layout and to have unique object representations. However, under gcc 7.1, only X is considered to have unique object representations, and only X and Y are considered to be standard-layout. (It looks like Y was incorrectly considered to not be standard-layout until PR 80605.) $ cat t.cc struct A {}; struct B : A {}; struct C : B {}; struct X : A { char c; }; struct Y : B { char c; }; struct Z : C { char c; }; static_assert(__has_unique_object_representations(X)); static_assert(__has_unique_object_representations(Y)); static_assert(__has_unique_object_representations(Z)); static_assert(__is_standard_layout(X)); static_assert(__is_standard_layout(Y)); static_assert(__is_standard_layout(Z)); $ g++-7 -Wall -Wextra -c t.cc -std=c++17 t.cc:8:1: error: static assertion failed static_assert(__has_unique_object_representations(Y)); ^~~~~~~~~~~~~ t.cc:9:1: error: static assertion failed static_assert(__has_unique_object_representations(Z)); ^~~~~~~~~~~~~ t.cc:12:1: error: static assertion failed static_assert(__is_standard_layout(Z)); ^~~~~~~~~~~~~ $ g++-7 -v Using built-in specs. COLLECT_GCC=g++-7 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 7.1.0-7' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=gcc4-compatible --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-initfini-array Thread model: posix gcc version 7.1.0 (Debian 7.1.0-7)
Hi, It still happens with gcc trunk. Note that you have this issue for example when you try to inherit from the boost/operators.hpp operators (eg boost::less_than_comparable<T>) and expect is_standard_layout to be true. One possible workaround in such case is to inherit from boost::less_than_comparable1<T> instead, that removes one inheritance level to workaround this gcc bug. Cheers, Romain
Hi, Note that in the meantime, this was fixed on trunk (gcc 8). I don't know when, but it was fixed between December 2017 and now, and don't know with which commit. Cheers, Romain
Fixed by r257745
According to the previous comment this depends on PR 82764 and the target milestone is 7.4
Let's call it a dup of PR 82764 then. *** This bug has been marked as a duplicate of bug 82764 ***