public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] C++: fix-it hint for removing stray semicolons
@ 2017-04-24 20:10 David Malcolm
  2017-04-25 11:48 ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: David Malcolm @ 2017-04-24 20:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

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

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 "" } */
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] C++: fix-it hint for removing stray semicolons
  2017-04-24 20:10 [PATCH] C++: fix-it hint for removing stray semicolons David Malcolm
@ 2017-04-25 11:48 ` Nathan Sidwell
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2017-04-25 11:48 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

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.


-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] C: fix-it hint for removing stray semicolons
  2017-04-24 19:48 [PATCH] C: " David Malcolm
@ 2017-04-25 11:46 ` Nathan Sidwell
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2017-04-25 11:46 UTC (permalink / raw)
  To: David Malcolm, gcc-patches

On 04/24/2017 03:58 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/c/ChangeLog:
> 	* c-parser.c (c_parser_struct_or_union_specifier): Add fix-it
> 	hint for removing extra semicolon.

ok


-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] C: fix-it hint for removing stray semicolons
@ 2017-04-24 19:48 David Malcolm
  2017-04-25 11:46 ` Nathan Sidwell
  0 siblings, 1 reply; 4+ messages in thread
From: David Malcolm @ 2017-04-24 19:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

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/c/ChangeLog:
	* c-parser.c (c_parser_struct_or_union_specifier): Add fix-it
	hint for removing extra semicolon.

gcc/testsuite/ChangeLog:
	* gcc.dg/semicolon-fixits.c: New test case.
---
 gcc/c/c-parser.c                        |  9 +++++++--
 gcc/testsuite/gcc.dg/semicolon-fixits.c | 17 +++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/semicolon-fixits.c

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 988369e..9398652 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -2948,8 +2948,13 @@ c_parser_struct_or_union_specifier (c_parser *parser)
 	  /* Parse any stray semicolon.  */
 	  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
 	    {
-	      pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
-		       "extra semicolon in struct or union specified");
+	      location_t semicolon_loc
+		= c_parser_peek_token (parser)->location;
+	      gcc_rich_location richloc (semicolon_loc);
+	      richloc.add_fixit_remove ();
+	      pedwarn_at_rich_loc
+		(&richloc, OPT_Wpedantic,
+		 "extra semicolon in struct or union specified");
 	      c_parser_consume_token (parser);
 	      continue;
 	    }
diff --git a/gcc/testsuite/gcc.dg/semicolon-fixits.c b/gcc/testsuite/gcc.dg/semicolon-fixits.c
new file mode 100644
index 0000000..e7d5322
--- /dev/null
+++ b/gcc/testsuite/gcc.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 semicolon in struct or union specified" } */
+/* { dg-begin-multiline-output "" }
+ struct s1 { int i;; };
+                   ^
+                   -
+   { dg-end-multiline-output "" } */
+
+/* Union with extra semicolon.  */
+union u1 { int i;; }; /* { dg-warning "18: extra semicolon in struct or union specified" } */
+/* { dg-begin-multiline-output "" }
+ union u1 { int i;; };
+                  ^
+                  -
+   { dg-end-multiline-output "" } */
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-25 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-24 20:10 [PATCH] C++: fix-it hint for removing stray semicolons David Malcolm
2017-04-25 11:48 ` Nathan Sidwell
  -- strict thread matches above, loose matches on Subject: below --
2017-04-24 19:48 [PATCH] C: " David Malcolm
2017-04-25 11:46 ` Nathan Sidwell

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).