From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 10/17] C++: provide fix-it hints in -Wsuggest-override
Date: Mon, 24 Jul 2017 19:31:00 -0000 [thread overview]
Message-ID: <1500926714-56988-11-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <1500926714-56988-1-git-send-email-dmalcolm@redhat.com>
This patch to the C++ frontend extends -Wsuggest-override so that the
suggestions contain fix-it hints, provided that it can get at the correct
location. Doing so requires the blt_node infrastructure.
gcc/cp/ChangeLog:
* class.c: Include "gcc-rich-location.h" and "blt.h".
(check_for_override): When suggesting functions that can be marked
"override", if the location is available via BLT nodes, add a
fix-it hint.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wsuggest-override.C: Add -fdiagnostics-show-caret and
-fblt to the options. Update expected output to show the fix-it
hints.
---
gcc/cp/class.c | 23 +++++++++++++++++++++--
gcc/testsuite/g++.dg/warn/Wsuggest-override.C | 12 +++++++++++-
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 0336ae5..6d0644d 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -37,6 +37,8 @@ along with GCC; see the file COPYING3. If not see
#include "gimplify.h"
#include "intl.h"
#include "asan.h"
+#include "gcc-rich-location.h"
+#include "blt.h"
/* Id for dumping the class hierarchy. */
int class_dump_id;
@@ -3024,8 +3026,25 @@ check_for_override (tree decl, tree ctype)
overrides_found = true;
if (warn_override && !DECL_OVERRIDE_P (decl)
&& !DECL_DESTRUCTOR_P (decl))
- warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
- "%qD can be marked override", decl);
+ {
+ gcc_rich_location richloc (DECL_SOURCE_LOCATION (decl));
+ /* Attempt to suggest adding " override" after the declarator
+ (and before the semicolon). */
+ blt_node *asnode = blt_get_node_for_tree (decl);
+ if (asnode)
+ {
+ /* Expect a member-declaration containing a
+ decl-specifier-seq declarator token(;).
+ We want the declarator. */
+ blt_node *declarator
+ = asnode->get_first_child_of_kind (BLT_DECLARATOR);
+ if (declarator)
+ richloc.add_fixit_insert_after (declarator->get_finish (),
+ " override");
+ }
+ warning_at_rich_loc (&richloc, OPT_Wsuggest_override,
+ "%qD can be marked override", decl);
+ }
}
if (DECL_VIRTUAL_P (decl))
diff --git a/gcc/testsuite/g++.dg/warn/Wsuggest-override.C b/gcc/testsuite/g++.dg/warn/Wsuggest-override.C
index f820f4b..8f5c133 100644
--- a/gcc/testsuite/g++.dg/warn/Wsuggest-override.C
+++ b/gcc/testsuite/g++.dg/warn/Wsuggest-override.C
@@ -1,5 +1,5 @@
// { dg-do compile }
-// { dg-options "-std=c++11 -Wsuggest-override" }
+// { dg-options "-std=c++11 -Wsuggest-override -fdiagnostics-show-caret -fblt" }
struct A
{
A();
@@ -16,8 +16,18 @@ struct B : A
B();
virtual ~B();
virtual void f(); // { dg-warning "can be marked override" }
+/* { dg-begin-multiline-output "" }
+ virtual void f();
+ ^
+ override
+ { dg-end-multiline-output "" } */
virtual int bar() override;
int c();
operator int();
virtual operator float(); // { dg-warning "can be marked override" }
+/* { dg-begin-multiline-output "" }
+ virtual operator float();
+ ^~~~~~~~
+ override
+ { dg-end-multiline-output "" } */
};
--
1.8.5.3
next prev parent reply other threads:[~2017-07-24 19:31 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-24 19:31 [PATCH 00/17] RFC: New source-location representation; Language Server Protocol David Malcolm
2017-07-24 19:31 ` [PATCH 01/17] Add param-type-mismatch.c/C testcases as a baseline David Malcolm
2017-07-24 19:56 ` Eric Gallager
2017-09-01 17:00 ` Jeff Law
2017-07-24 19:31 ` David Malcolm [this message]
2017-07-24 19:31 ` [PATCH 11/17] Add JSON implementation David Malcolm
2017-09-01 17:06 ` Jeff Law
2017-07-24 19:31 ` [PATCH 12/17] Add server.h and server.c David Malcolm
2017-07-26 14:35 ` Oleg Endo
2017-07-26 14:50 ` David Malcolm
2017-07-26 21:00 ` Mike Stump
2017-09-01 17:09 ` Jeff Law
2017-07-24 19:31 ` [PATCH 03/17] Core of BLT implementation David Malcolm
2017-09-01 17:32 ` Jeff Law
2017-07-24 19:31 ` [PATCH 15/17] Language Server Protocol: add lsp::server abstract base class David Malcolm
2017-07-27 4:14 ` Trevor Saunders
2017-07-28 14:48 ` David Malcolm
2017-07-27 7:55 ` Richard Biener
2017-07-28 16:02 ` David Malcolm
2017-07-24 19:31 ` [PATCH 02/17] diagnostics: support prefixes within diagnostic_show_locus David Malcolm
2017-09-01 17:11 ` Jeff Law
2017-07-24 19:31 ` [PATCH 17/17] Language Server Protocol: work-in-progess on testsuite David Malcolm
2017-07-24 19:31 ` [PATCH 13/17] Add http-server.h and http-server.c David Malcolm
2017-07-24 19:38 ` [PATCH 14/17] Add implementation of JSON-RPC David Malcolm
2017-07-24 19:38 ` [PATCH 07/17] C++: use BLT to highlight parameter of callee decl for mismatching types David Malcolm
2017-07-24 19:38 ` [PATCH 06/17] C: " David Malcolm
2017-07-24 19:39 ` [PATCH 09/17] C++: highlight return types when complaining about mismatches David Malcolm
2017-07-24 19:39 ` [PATCH 08/17] C: " David Malcolm
2017-07-24 19:39 ` [PATCH 04/17] C frontend: capture BLT information David Malcolm
2017-07-27 19:58 ` Martin Sebor
2017-07-24 19:40 ` [PATCH 05/17] C++ " David Malcolm
2017-07-24 19:41 ` [PATCH 16/17] Language Server Protocol: proof-of-concept GCC implementation David Malcolm
2017-07-26 17:10 ` [PATCH 00/17] RFC: New source-location representation; Language Server Protocol Jim Wilson
2017-07-28 5:12 ` Alexandre Oliva
2017-07-27 19:51 ` Martin Sebor
2017-07-28 14:28 ` David Malcolm
2017-07-28 18:32 ` Martin Sebor
2017-10-11 19:32 ` David Malcolm
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=1500926714-56988-11-git-send-email-dmalcolm@redhat.com \
--to=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).