On Tue, May 24, 2022 at 09:59:03AM -0400, David Malcolm wrote:
> > 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?

Done, see another mail.

> 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.

--- pr91134.c
+++ pr91134.c
@@ -10,19 +10,19 @@
   struct X *pointer = &x;
   struct Y *yp = &y;
   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 i = *(*pointerpointer)->member;  /* { dg-error "'pointerpointer' is a 
pointer to pointer; did you mean to dereference it before applying '->' to 
it\\\?" } */
 /* { dg-begin-multiline-output "" }
    int i = *pointerpointer->member;
                           ^~
             (*            )
    { dg-end-multiline-output "" } */
-  int j = pointer.member;              /* { dg-error "'pointer' is a pointer; 
did you mean to use '->'\\\?" } */
+  int j = pointer->member;             /* { dg-error "'pointer' is a pointer; 
did you mean to use '->'\\\?" } */
 /* { dg-begin-multiline-output "" }
    int j = pointer.member;
                   ^
                   ->
    { dg-end-multiline-output "" } */
-  int k = yp->x->member;               /* { dg-error "'yp->x' is a pointer to 
pointer; did you mean to dereference it before applying '->' to it\\\?" } */
+  int k = (*yp->x)->member;            /* { dg-error "'yp->x' is a pointer to 
pointer; did you mean to dereference it before applying '->' to it\\\?" } */
 /* { dg-begin-multiline-output "" }
    int k = yp->x->member;
                 ^~

The second and third change actually fix those issues and make it compile,
the first one will generate a different error, because the right
change in that case is int i = (*pointerpointer)->member;
but guessing that in the compiler would be too hard, when
parsing pointerpointer->member we really don't know that
there is * before it...

        Jakub

Reply via email to