<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64619>64619</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missing diagnostic for non-standard layout types in `offsetof`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Endilll
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2P4ygT_jWVS8mWDfHXwYd8tEdzGL2HV9qZPkXYlBN2CFiA05M97G9f4aS7p3e7pTnsYRESCX6q4KmqpxDeq6MhaqHYQrFfiTmcrGsfjFRa61Vv5bXdWeOVJIfhRDhare2TMkekH-I8aUJg9SmEyQPfAOuAdUcre6tDat0RWPcHsM5W1SU3QjbAmgjL9pBtoMxuc5im244Pbh4CfssRqi0qE1AA3y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