Bug 81976 - bad is_standard_layout/has_unique_object_representations results with a chain of empty bases
Summary: bad is_standard_layout/has_unique_object_representations results with a chain...
Status: RESOLVED DUPLICATE of bug 82764
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid, wrong-code
Depends on:
Blocks:
 
Reported: 2017-08-25 01:11 UTC by Joshua Oreman
Modified: 2018-05-03 07:15 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Oreman 2017-08-25 01:11:12 UTC
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)
Comment 1 Romain Geissler 2017-12-18 22:36:36 UTC
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
Comment 2 Romain Geissler 2018-03-03 14:36:36 UTC
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
Comment 3 Jonathan Wakely 2018-03-05 11:41:01 UTC
Fixed by r257745
Comment 4 Pádraig Brady 2018-05-03 03:31:28 UTC
According to the previous comment this depends on PR 82764
and the target milestone is 7.4
Comment 5 Jonathan Wakely 2018-05-03 07:15:22 UTC
Let's call it a dup of PR 82764 then.

*** This bug has been marked as a duplicate of bug 82764 ***