<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64154>64154</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrectly rejecting qualified names as a member designator of offsetof
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c,
c++,
rejects-valid
</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/jzTKMdMdn):
```cpp
#include <cstddef>
struct X2 {
int field;
};
static_assert(offsetof(X2, X2::field) == 0);
static_assert(__builtin_offsetof(X2, X2::field) == 0);
```
Clang issues the following errors:
```
<source>:7:30: error: expected ')'
7 | static_assert(offsetof(X2, X2::field) == 0);
| ^
<source>:7:15: note: to match this '('
7 | static_assert(offsetof(X2, X2::field) == 0);
| ^
/opt/compiler-explorer/clang-trunk-20230727/lib/clang/18/include/stddef.h:116:42: note: expanded from macro 'offsetof'
116 | #define offsetof(t, d) __builtin_offsetof(t, d)
| ^
<source>:8:40: error: expected ')'
8 | static_assert(__builtin_offsetof(X2, X2::field) == 0);
| ^
<source>:8:33: note: to match this '('
8 | static_assert(__builtin_offsetof(X2, X2::field) == 0);
```
GCC, EDG, and MSVC accept the code.
The C++ Standard [says](http://eel.is/c++draft/support.types.layout#1.sentence-1) the following: _The macro offsetof(type, member-designator) has the same semantics as the corresponding macro in the C standard library header [<stddef.h>], but accepts a restricted set of type arguments in this document._
C23 (N3096) ยง7.21 p4: <...> _the value of which is the offset in bytes, to the subobject (designated by member-designator), from the beginning of any object of type type. The type and member designator shall be such that given_ `static type t;` _then the expression &(t. member-designator) evaluates to an address constant._
Since in C++ qualified names are allowed to the right of dot, `&(x2.X2::field)` is a well-formed expression ([CE](https://godbolt.org/z/8Yfz33e89)). I believe it's in the spirit of the wording to accept aforementioned example.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vt2O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