public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Martin Sebor <msebor@gmail.com>, Jason Merrill <jason@redhat.com>
Cc: Eric Gallager <egall@gwmail.gwu.edu>,
	gcc-patches List	 <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] v3: C/C++: add fix-it hints for missing '&' and '*' (PR c++/87850)
Date: Fri, 30 Nov 2018 15:27:00 -0000	[thread overview]
Message-ID: <1543591622.4619.123.camel@redhat.com> (raw)
In-Reply-To: <6df7e9b0-9bb7-5d75-5b78-0776b620e7fb@gmail.com>

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	other threads:[~2018-11-30 15:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-09 22:36 [PATCH] " David Malcolm
2018-11-10  7:01 ` Eric Gallager
2018-11-11 18:01   ` Martin Sebor
2018-11-11 21:02     ` David Malcolm
2018-11-12 21:32       ` Martin Sebor
2018-11-13 21:34         ` Jason Merrill
2018-11-15 21:48           ` [PATCH] v2: " David Malcolm
2018-11-16 18:13             ` Jason Merrill
2018-11-19 21:23               ` [PATCH] v3: " David Malcolm
2018-11-20  2:46                 ` Joseph Myers
2018-11-20 22:05                   ` David Malcolm
2018-11-20 22:23                     ` Joseph Myers
2018-11-30 23:01                       ` [PATCH] v4: " David Malcolm
2018-12-01 18:38                         ` Jason Merrill
2018-12-03 22:14                           ` Joseph Myers
2018-12-05 16:03                             ` Jason Merrill
2018-12-05 16:18                               ` David Malcolm
2018-11-21  0:36                 ` [PATCH] v3: " Jeff Law
2018-11-21  0:39                 ` Martin Sebor
2018-11-30 15:27                   ` David Malcolm [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1543591622.4619.123.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=egall@gwmail.gwu.edu \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).