From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116100 invoked by alias); 3 Jul 2017 19:34:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 116091 invoked by uid 89); 3 Jul 2017 19:34:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*M:111, aloud X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Jul 2017 19:33:52 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF3E285A07; Mon, 3 Jul 2017 19:33:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF3E285A07 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dmalcolm@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CF3E285A07 Received: from ovpn-117-117.phx2.redhat.com (ovpn-117-117.phx2.redhat.com [10.3.117.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EFDD5D969; Mon, 3 Jul 2017 19:33:50 +0000 (UTC) Message-ID: <1499110429.7656.111.camel@redhat.com> Subject: Re: [PATCH] C/C++: add fix-it hints for various missing symbols From: David Malcolm To: Richard Sandiford Cc: gcc-patches@gcc.gnu.org Date: Mon, 03 Jul 2017 19:34:00 -0000 In-Reply-To: <87y3s5pcvm.fsf@linaro.org> References: <1499107059-28855-1-git-send-email-dmalcolm@redhat.com> <87y3s5pcvm.fsf@linaro.org> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg00142.txt.bz2 On Mon, 2017-07-03 at 19:57 +0100, Richard Sandiford wrote: > [Thanks for all your diagnostic work btw.] > > David Malcolm 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. :-) My plan was to only do it for open/close punctuation, i.e.: * '(' and ')' * '{' and '}' * '[' and ']' * maybe '<' and '>' in C++ > 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? Good idea: if it's on the same line, use a secondary range; if it's on a different line, use a note. The above example would look something like this (with the '[' as a secondary range): missing-symbol-2.c:25:22: error: expected ']' const char test [42; ~ ^ ] which is more compact than the "separate note" approach, whilst (IMHO) being just as readable. FWIW diagnostic-show-locus.c can handle widely-separated secondary ranges within one rich_location, provided they're in the same source file (see calculate_line_spans, and the start_span callback within diagnostic_context). Consider the unclosed namespace here: $ cat -n test.cc 1 namespace ns { 2 3 void test () 4 { 5 } for which we currently emit the rather unhelpful: $ gcc test.cc test.cc:5:1: error: expected ‘}’ at end of input } ^ Printing it via a secondary range using a single rich_location with just an "error_at_rich_loc" call would print something like: test.cc:5:1: error: expected ‘}’ at end of input test.cc:1:14: namespace ns { ^ test.cc:5:1: } ^ } which works, but I'm not a fan of. In constrast, with the "if it's on a different line, use a note" approach, we would print: test.cc:5:1: error: expected ‘}’ at end of input } ^ } test.cc:1:14: note: to match this '{' namespace ns { ^ which I think is better (and supports the cases where they're in different files (e.g. you have a stray unclosed namespace in a header file, somewhere...), or macros are involved, etc) So I'll have a go at implementing the "is it on a different line" logic you suggest. For reference, clang prints the following for the above case: test.cc:5:2: error: expected '}' } ^ test.cc:1:14: note: to match this '{' namespace ns { ^ Thinking aloud, maybe it would be better for the fix-it hint to suggest putting the '}' on a whole new line. Might even be good to suggest adding } // namespace ns or similar (for this specific case), giving this output: test.cc:5:1: error: expected ‘}’ at end of input } +} // namespace ns test.cc:1:14: note: to match this '{' namespace ns { ^ (only works if the proposed insertion point is on the end of a line, given the current restrictions on what our fix-it machinery is capable of - we don't currently support splitting a pre-existing line via a fix-it hint) Thanks. Dave