[Bug c/79775] Confusing fix-it diagnostics with double pointers to structs

2019-06-13 Thread felix.von.s at posteo dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79775

--- Comment #3 from felix  ---
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.

[Bug c/79775] Confusing fix-it diagnostics with double pointers to structs

2018-11-07 Thread tschwinge at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79775

Thomas Schwinge  changed:

   What|Removed |Added

   Last reconfirmed|2017-03-01 00:00:00 |2018-11-7
 CC||dmalcolm at gcc dot gnu.org,
   ||tschwinge at gcc dot gnu.org

--- Comment #2 from Thomas Schwinge  ---
I ran into such a thing, too (with today's GCC trunk r265867):

struct s
{
  int m;
};

void f(struct s **s)
{
  *s->m = 5;
  // (*s)->m = 5;
}

C:

../f.c: In function 'f':
../f.c:8:5: error: '*s' is a pointer; did you mean to use '->'?
8 |   *s->m = 5;
  | ^~
  | ->

C++:

../f.c: In function 'void f(s**)':
../f.c:8:7: error: request for member 'm' in '* s', which is of pointer
type 's*' (maybe you meant to use '->' ?)
8 |   *s->m = 5;
  |   ^

[Bug c/79775] Confusing fix-it diagnostics with double pointers to structs

2017-03-01 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79775

Marek Polacek  changed:

   What|Removed |Added

   Keywords||diagnostic
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-03-01
 CC||mpolacek at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Marek Polacek  ---
Confirmed.