Hi,
Consider the following code:
#include <type_traits>
struct A {};
struct B : A { char ch; };
struct C : A {
B b;
};
static_assert(std::is_standard_layout_v<C>);
static_assert(sizeof(C) == 2);
In my reading of https://eel.is/c++draft/class.prop#3 C is standard-
layout. GCC with libstdc++ agrees.
Is this a defect, or did I make a mistake somewhere in my reasoning?
Interesting… 3.7’s footnote is definitely the intended effect, but yeah, it doesn’t look like 3.7 actually does what the footnote says in the case you found.
Playing around, I noticed this:
struct X { };
struct Y {
X x;
};
struct Z : X {
Y y;
};
By 3.7, Z is definitely not standard-layout, but GCC thinks it is. So GCC’s implementation of the rule is wrong. Clang and MSVC get Z correctly labeled as non-standard-layout.
Melissa