C++ Standard in point 12.3.1 says:
If a standard-layout union contains several standard-layout structs that share a common initial sequence, and if a non-static data member of an object of this standard-layout union type is active and is one of the standard-layout structs, it is permitted to inspect the common initial sequence of any of the standard-layout struct members;
However following code doesn't compile on any major compiler (https://godbolt.org/z/3jM1co):
struct type {
union {
int a;
int b;
};
constexpr type(int n) : a(n) {}
};
constexpr int fun(int n) {
type t(n);
return t.b;
}
constexpr int res = fun(5);
Why code doesn't compile (I belive that all compilers aren't wrong here)? This code should meet the conditions for accessing technically inactive member of a union (standard layout, common initial sequence). When constexpr keyword is removed this code compiles without a problem.