public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@linaro.org>
To: David Malcolm <dmalcolm@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [committed] diagnostics: support compact printing of secondary locations
Date: Tue, 11 Jul 2017 17:34:00 -0000	[thread overview]
Message-ID: <87tw2iswse.fsf@linaro.org> (raw)
In-Reply-To: <1499784198-36796-1-git-send-email-dmalcolm@redhat.com> (David	Malcolm's message of "Tue, 11 Jul 2017 10:43:18 -0400")

David Malcolm <dmalcolm@redhat.com> writes:
> On Mon, 2017-07-03 at 19:57 +0100, Richard Sandiford wrote:
>> [Thanks for all your diagnostic work btw.]
>> 
>> David Malcolm <dmalcolm@redhat.com> writes:
>> > clang can also print notes about matching opening symbols
>> > e.g. the note here:
>> > 
>> >   missing-symbol-2.c:25:22: error: expected ']'
>> >     const char test [42;
>> >                        ^
>> >   missing-symbol-2.c:25:19: note: to match this '['
>> >     const char test [42;
>> >                     ^
>> > which, although somewhat redundant for this example, seems much
>> > more
>> > useful if there's non-trivial nesting of constructs, or more than a
>> > few
>> > lines separating the open/close symbols (e.g. showing a stray
>> > "namespace {"
>> > that the user forgot to close).
>> > 
>> > I'd like to implement both of these ideas as followups, but in
>> > the meantime, is the fix-it hint patch OK for trunk?
>> > (successfully bootstrapped & regrtested on x86_64-pc-linux-gnu)
>> 
>> Just wondering: how easy would it be to restrict the note to the
>> kinds
>> of cases you mention?  TBH I think clang goes in for extra notes too
>> much, and it's not always that case that an "expected 'foo'" message
>> really is caused by a missing 'foo'.  It'd be great if there was some
>> way of making the notes a bit more discerning. :-)
>> 
>> Or maybe do something like restrict the extra note to cases in which
>> the
>> opening character is on a different line and use an underlined range
>> when the opening character is on the same line?
>> 
>> Thanks,
>> Richard
>
> Thanks.
>
> This patch implements a new method:
>
>    bool gcc_rich_location::add_location_if_nearby (location_t);
>
> to make it easy for a diagnostic to compactly print secondary locations
> for these kinds of cases, falling back to printing them via a note
> otherwise.
>
> Usage example (adapted from the one in the header):
>
>   gcc_rich_location richloc (primary_loc);
>   bool added secondary = richloc.add_location_if_nearby (secondary_loc);
>   error_at_rich_loc (&richloc, "missing %qs", "}");
>   if (!added secondary)
>     inform (secondary_loc, "here's the associated %qs", "{");
>
> When primary_loc and secondary_loc are on the same line this will print:
>
>   test.c:1:39: error: missing '}'
>    struct same_line { double x; double y; ;
>                     ~                    ^
>
> When they are on different lines, this will print:
>
>   test.c:6:1: error: missing '}'
>    ;
>    ^
>   test.c:3:1: note: here's the associated '{'
>    {
>    ^

Thanks, this looks great!

Richard

  reply	other threads:[~2017-07-11 17:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-03 18:04 [PATCH] C/C++: add fix-it hints for various missing symbols David Malcolm
2017-07-03 18:57 ` Richard Sandiford
2017-07-03 19:34   ` David Malcolm
2017-07-11 14:09   ` [committed] diagnostics: support compact printing of secondary locations David Malcolm
2017-07-11 17:34     ` Richard Sandiford [this message]
2017-07-03 23:01 ` [PATCH] C/C++: add fix-it hints for various missing symbols Joseph Myers
2017-07-05 15:32   ` David Malcolm
2017-07-05 16:17     ` Joseph Myers
2017-08-28 16:11 ` Jeff Law
2017-09-26 13:56 ` [PATCH 0/2] " David Malcolm
2017-09-26 13:56   ` [PATCH 1/2] C++: avoid partial duplicate implementation of cp_parser_error David Malcolm
2017-10-11 17:26     ` PING: " David Malcolm
2017-10-11 21:21     ` Jason Merrill
2017-10-12 18:10       ` David Malcolm
2017-09-26 13:56   ` [PATCH 2/2] C/C++: add fix-it hints for various missing symbols (v2) David Malcolm
2017-10-05 16:08     ` [PATCH 2/2] C/C++: add fix-it hints for various missing symbols (v3) David Malcolm
2017-10-11 17:27       ` PING " David Malcolm
2017-10-12  5:23       ` Jason Merrill

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=87tw2iswse.fsf@linaro.org \
    --to=richard.sandiford@linaro.org \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).