On Tue, 2018-11-20 at 17:39 -0700, Martin Sebor wrote:
> > +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.

I definitely prefer the style of the output in your example, but I
think there's a "data model vs presentation" thing going on here.

I'd prefer to avoid the underlying rich_location using replacement when
we mean insertion, for the same reasons as for deletion discussed at
[1]

I think the issue here is with the presentation of insertion fix-it
hints in diagnostic-show-locus.c: there's currently no way for the user
to tell if this:

  takes_int_ptr(ivar);
                ^~~~
                &

means:
  (a) replace "ivar" with "&", or
  (b) insert "&" in front of "ivar" (the intended behavior)

and this alternative presentation would definitely be clearer:

  takes_int_ptr(ivar);
                ^~~~
                &ivar

I can have a look at reimplementing how we present insertions in
diagnostic-show-locus.c.

Dave

[1] 
https://gcc.gnu.org/onlinedocs/gccint/Guidelines-for-Diagnostics.html#Express-deletion-in-terms-of-deletion_002c-not-replacement

Reply via email to