Issue 64619
Summary Missing diagnostic for non-standard layout types in `offsetof`
Labels clang:diagnostics
Assignees
Reporter Endilll
    Consider the following example (https://godbolt.org/z/o77v1nad9):
```cpp
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](http://eel.is/c++draft/support.types.layout#1.sentence-2).
```
<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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to