Closed
Description
Consider the following example (https://godbolt.org/z/o77v1nad9):
struct X1 { int a; };
struct X2 { int b; };
struct Y : X1, X2 {};
static_assert(__builtin_offsetof(Y, b) == 4);
static_assert(offsetof(Y, b) == 4);
static_assert(!std::is_standard_layout_v<Y>, "");
Only GCC warns that non-standard layout type is passed to offsetof
, which is conditionally-supported.
<source>:8:34: warning: 'offsetof' within non-standard-layout type 'Y' is conditionally-supported [-Winvalid-offsetof]
8 | static_assert(__builtin_offsetof(Y, b) == 4);
| ~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /opt/compiler-explorer/gcc-trunk-20230811/include/c++/14.0.0/cstddef:50,
from <source>:1:
<source>:9:24: warning: 'offsetof' within non-standard-layout type 'Y' is conditionally-supported [-Winvalid-offsetof]
9 | static_assert(offsetof(Y, b) == 4);
| ^
GCC issues it by default, whereas Clang, MSVC, and EDG doesn't even in pedantic modes (or /W4
).
I'm not sure what the solution should be, but I feel like there is a problem to solve.