+void test_2 (void)
+{
+  takes_int_ptr(ivar); /* { dg-warning "" "" { target c } } */
+  /* { dg-error "" "" { target c++ } .-1 } */
+  /* { dg-message "possible fix: take the address with '&'" "" { target *-*-* 
} .-2 } */
+
+  /* Expect an '&' fix-it hint.  */
+  /* { dg-begin-multiline-output "" }
+   takes_int_ptr(ivar);
+                 ^~~~
+                 |
+                 int
+     { dg-end-multiline-output "" } */
+  /* { dg-begin-multiline-output "" }
+   takes_int_ptr(ivar);
+                 ^~~~
+                 &

I experimented with adding hints to sizeof_pointer_memaccess_warning
over the weekend and ran into a location difference between the two
front-ends.  In an attempt to resolve it, rather than using
an "insertion hint" like I think you did above, I used a replacement
hint.  And although it started out as a workaround I ended up liking
the result better.  What I think the same approach would result in
here is something like:

  takes_int_ptr(ivar);
  note: possible fix: take the address with '&'
  note: takes_int_ptr(ivar);
                      ^~~~
                      |
                      int
   note: takes_int_ptr(ivar);
                       ^~~~
                       &ivar

Have you considered this style, i.e., printing valid expressions
in the hints when possible rather than just operators?  It solves
the problem of the lone operators looking a little too terse and
cryptic.

I realize it's not always possible (not every fix-it hint is for
a bad expression) but I'm wondering if it would be worth using
when it is.

Martin

Reply via email to