https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81976
Bug ID: 81976 Summary: bad is_standard_layout/has_unique_object_representations results with a chain of empty bases Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: oremanj at mit dot edu Target Milestone: --- 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)