diff mbox

C++: fix-it hint for removing stray semicolons

Message ID 1493063953-51717-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm April 24, 2017, 7:59 p.m. UTC
Patch adds a fix-it hint to a pre-existing pedwarn to make
it easier for IDEs to assist in fixing the mistake.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/cp/ChangeLog:
	* parser.c (cp_parser_member_declaration): Add fix-it hint
	for removing stray semicolons.

gcc/testsuite/ChangeLog:
	* g++.dg/semicolon-fixits.C: New test case.
---
 gcc/cp/parser.c                         |  6 +++++-
 gcc/testsuite/g++.dg/semicolon-fixits.C | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/semicolon-fixits.C

Comments

Nathan Sidwell April 25, 2017, 11:41 a.m. UTC | #1
On 04/24/2017 03:59 PM, David Malcolm wrote:
> Patch adds a fix-it hint to a pre-existing pedwarn to make
> it easier for IDEs to assist in fixing the mistake.
> 
> Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.
> 
> OK for trunk?
> 
> gcc/cp/ChangeLog:
> 	* parser.c (cp_parser_member_declaration): Add fix-it hint
> 	for removing stray semicolons.

ok.
diff mbox

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f164d7e..9d5baf8 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -23123,7 +23123,11 @@  cp_parser_member_declaration (cp_parser* parser)
 	{
 	  cp_token *token = cp_lexer_peek_token (parser->lexer);
 	  if (!in_system_header_at (token->location))
-	    pedwarn (token->location, OPT_Wpedantic, "extra %<;%>");
+	    {
+	      gcc_rich_location richloc (token->location);
+	      richloc.add_fixit_remove ();
+	      pedwarn_at_rich_loc (&richloc, OPT_Wpedantic, "extra %<;%>");
+	    }
 	}
       else
 	{
diff --git a/gcc/testsuite/g++.dg/semicolon-fixits.C b/gcc/testsuite/g++.dg/semicolon-fixits.C
new file mode 100644
index 0000000..a9cc783
--- /dev/null
+++ b/gcc/testsuite/g++.dg/semicolon-fixits.C
@@ -0,0 +1,17 @@ 
+/* { dg-options "-fdiagnostics-show-caret -Wpedantic" } */
+
+/* Struct with extra semicolon.  */
+struct s1 { int i;; }; /* { dg-warning "19: extra .;." } */
+/* { dg-begin-multiline-output "" }
+ struct s1 { int i;; };
+                   ^
+                   -
+   { dg-end-multiline-output "" } */
+
+/* Union with extra semicolon.  */
+union u1 { int i;; }; /* { dg-warning "18: extra .;." } */
+/* { dg-begin-multiline-output "" }
+ union u1 { int i;; };
+                  ^
+                  -
+   { dg-end-multiline-output "" } */