<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/101829>101829</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `__builtin_offsetof` in clang does not support qualified member name
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Ming-3364
      </td>
    </tr>
</table>

<pre>
    Consider the following code:

```c++
#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:

```c++
<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.

[https://godbolt.org/z/favKoPaTv](https://godbolt.org/z/favKoPaTv)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVV2P6yYQ_TXkZZTIAX_lwQ_Z7LVUVZX6cN8jDOOYFoPL4Oxuf32FnTTp1d7qVmpkEQuYmXMOZ4wkMheH2LDihRWvGznHwYfmF-MuWyHKfNN5_dGcvCOjMUAcEHpvrX8z7gLKa2TiyLJXlt3HMlsfxfhLetZZLoxTdtYITJwURa2xZ-LLukoxzCpCR6x6MS5Cx8QLq17T-LweKTJxXHat8wAAapBhDVgLPYWto5yjB9_3TLz6vieMvme8Trn4qaOEXhw7xg-PsDuD5yxfB0NgCAL-hiqihu4DlJX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