`__builtin_offsetof` in clang does not support qualified member name
Consider the following code:
#include <cstddef>
struct bs{int b;};
struct tst:bs{
char b;
};
auto off=offsetof(tst,bs::b);
This is rejected by clang with the following diagnostic:
<source>:7:25: error: expected ')'
7 | auto off=offsetof(tst,bs::b);
| ^
<source>:7:10: note: to match this '('
7 | auto off=offsetof(tst,bs::b);
| ^
/opt/compiler-explorer/clang-trunk-20240803/lib/clang/20/include/__stddef_offsetof.h:16:42: note: expanded from macro 'offsetof'
16 | #define offsetof(t, d) __builtin_offsetof(t, d)
In fact, calling the__builtin_offsetof function with a qualified member name as its second parameter is always rejected by clang. This seems unreasonable, as using qualified name is necessary in some special cases. For example, in the test above, b and bs::b do not actually refer to the same variable.
Additionally, the error message provided by clang is also somewhat confusing.
@llvm/issue-subscribers-clang-frontend
Author: Raki (Ming-3364)
#include <cstddef>
struct bs{int b;};
struct tst:bs{
char b;
};
auto off=offsetof(tst,bs::b);
This is rejected by clang with the following diagnostic:
<source>:7:25: error: expected ')'
7 | auto off=offsetof(tst,bs::b);
| ^
<source>:7:10: note: to match this '('
7 | auto off=offsetof(tst,bs::b);
| ^
/opt/compiler-explorer/clang-trunk-20240803/lib/clang/20/include/__stddef_offsetof.h:16:42: note: expanded from macro 'offsetof'
16 | #define offsetof(t, d) __builtin_offsetof(t, d)
In fact, calling the__builtin_offsetof function with a qualified member name as its second parameter is always rejected by clang. This seems unreasonable, as using qualified name is necessary in some special cases. For example, in the test above, b and bs::b do not actually refer to the same variable.
Additionally, the error message provided by clang is also somewhat confusing.
Duplicate of #64154