On Tue, 2022-05-24 at 09:57 -0400, David Malcolm wrote: > On Tue, 2022-05-24 at 09:25 +0200, Jakub Jelinek via Gcc-patches > wrote: > > Hi! > > > > On the following testcase (the first dg-error line) we emit a weird > > diagnostics and even fixit on pointerpointer->member > > where pointerpointer is pointer to pointer to struct and we say > > 'pointerpointer' is a pointer; did you mean to use '->'? > > The first part is indeed true, but suggesting -> when the code > > already > > does use -> is confusing. > > The following patch adjusts callers so that they tell it if it is > > from > > . parsing or from -> parsing and in the latter case suggests to > > dereference > > the left operand instead by adding (* before it and ) after it > > (before ->). > > Or would a suggestion to add [0] before -> be better? > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for > > trunk? > > > > [...snip implementation...] > > > > > --- gcc/testsuite/gcc.dg/pr91134.c.jj 2022-05-23 > > 20:31:11.751001817 > > +0200 > > +++ gcc/testsuite/gcc.dg/pr91134.c 2022-05-23 > > 20:30:45.291268997 > > +0200 > > @@ -0,0 +1,13 @@ > > +/* PR c/91134 */ > > + > > +struct X { int member; } x; > > + > > +int > > +foo (void) > > +{ > > + struct X *pointer = &x; > > + struct X **pointerpointer = &pointer; > > + int i = *pointerpointer->member; /* { dg-error > > "'pointerpointer' is a pointer to pointer; did you mean to > > dereference it before applying '->' to it\\\?" } */ > > + int j = pointer.member; /* { dg-error "'pointer' is > > a > > pointer; did you mean to use '->'\\\?" } */ > > + return i + j; > > +} > > Ideally we'd have an automated check that the fix-it hint fixes the > code, but failing that, I like to have at least some DejaGnu test > coverage for fix-it hints - something like the tests in > gcc.dg/fixits.c > or gcc.dg/semicolon-fixits.c, perhaps?
Also, what does the output from: -fdiagnostics-generate-patch look like? That's usually the best way of checking if we're generating good fix-it hints. Dave