https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79775

--- Comment #3 from felix <felix.von.s at posteo dot de> ---
A particularly amusing variant of this bug occurs with the following code:

    struct x { struct x **xx; };

    int y = __builtin_offsetof(struct x, xx->xx);

which gives the warning

    $ gcc xx.c
    xx.c:3:40: error: ‘*0->xx’ is a pointer; did you mean to use ‘->’?
     int y = __builtin_offsetof(struct x, xx->xx);
                                            ^~
                                            ->
mentioning `*0`, which doesn't appear in the source code at all. Similarly for
C++:

    $ g++ xx.c
    xx.c:3:42: error: request for member ‘xx’ in ‘*((x*)0)->x::xx’, which is of
pointer type ‘x*’ (maybe you meant to use ‘->’ ?)
     int y = __builtin_offsetof(struct x, xx->xx);
                                              ^~

Compare The Other Compiler, which refuses to parse `->` inside
`__builtin_offsetof` altogether:

    $ clang xx.c
    xx.c:3:40: error: expected ')'
    int y = __builtin_offsetof(struct x, xx->xx);
                                           ^
    xx.c:3:27: note: to match this '('
    int y = __builtin_offsetof(struct x, xx->xx);
                              ^
    1 error generated.

I assume GCC parses it in order to have a more user-friendly ‘cannot apply
‘offsetof’ to a non constant address’ error, but I'm not sure if this is worth
it.

Reply via email to