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

            Bug ID: 109795
           Summary: is_standard_layout incorrect for colliding member and
                    base class
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: myriachan at gmail dot com
  Target Milestone: ---

The following compiles on GCC 13.1.0 when it should not:

struct X { };
struct Y {
    X x;
};
struct Z : X {
    Y y;
};
static_assert(!__is_standard_layout(Z));

By [class.prop]/3.7, rule 3.7.2 makes M(Z) = { Y } union M(Y).  Applying 3.7.2
recursively results in M(Y) = { X } union M(X).  By rule 3.7.1, M(X) = { }.  So
M(Z) = { Y, X }.  By rule 3.7, Z is not standard-layout, because Z's base class
X is an element of M(Z) = { Y, X }.

https://gcc.godbolt.org/z/oWhc8vs6z

Reply via email to