diff mbox

[committed] C: Fix missing spaces in 'struct' fix-it hints

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

Commit Message

David Malcolm Sept. 1, 2016, 1:21 a.m. UTC
In r237714 I added fix-it hints to the C frontend for missing "struct"
keywords e.g.:

spellcheck-typenames.c:69:1: error: unknown type name ‘foo_t’; use
‘struct’ keyword to refer to the type
 foo_t *foo_ptr;
 ^~~~~
 struct 

However when using the (not yet in trunk) option
 -fdiagnostics-generate-patch,
the generated patch is nonsensical:

  -foo_t *foo_ptr;
  +structfoo_t *foo_ptr;

Fix the fix-its by adding a trailing space to each one, giving:

  -foo_t *foo_ptr;
  +struct foo_t *foo_ptr;

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

Committed to trunk as r239912, as obvious.

gcc/c/ChangeLog:
	* c-parser.c (c_parser_declaration_or_fndef): Add trailing space
	to the insertion fixits for "struct", "union", and "enum".

---
 gcc/c/c-parser.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Andreas Schwab Sept. 1, 2016, 7:24 a.m. UTC | #1
On Sep 01 2016, David Malcolm <dmalcolm@redhat.com> wrote:

> diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> index a6281fc..531d94e 100644
> --- a/gcc/c/c-parser.c
> +++ b/gcc/c/c-parser.c
> @@ -1685,7 +1685,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
>        if (tag_exists_p (RECORD_TYPE, name))
>  	{
>  	  /* This is not C++ with its implicit typedef.  */
> -	  richloc.add_fixit_insert ("struct");
> +	  richloc.add_fixit_insert ("struct ");

Perhaps add_fixit_insert should receive a second argument that says
whether to prepend/append a space when inserting.  Then it can avoid
printing the space when the hint is displayed.

Andreas.
diff mbox

Patch

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a6281fc..531d94e 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1685,7 +1685,7 @@  c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
       if (tag_exists_p (RECORD_TYPE, name))
 	{
 	  /* This is not C++ with its implicit typedef.  */
-	  richloc.add_fixit_insert ("struct");
+	  richloc.add_fixit_insert ("struct ");
 	  error_at_rich_loc (&richloc,
 			     "unknown type name %qE;"
 			     " use %<struct%> keyword to refer to the type",
@@ -1693,7 +1693,7 @@  c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
 	}
       else if (tag_exists_p (UNION_TYPE, name))
 	{
-	  richloc.add_fixit_insert ("union");
+	  richloc.add_fixit_insert ("union ");
 	  error_at_rich_loc (&richloc,
 			     "unknown type name %qE;"
 			     " use %<union%> keyword to refer to the type",
@@ -1701,7 +1701,7 @@  c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
 	}
       else if (tag_exists_p (ENUMERAL_TYPE, name))
 	{
-	  richloc.add_fixit_insert ("enum");
+	  richloc.add_fixit_insert ("enum ");
 	  error_at_rich_loc (&richloc,
 			     "unknown type name %qE;"
 			     " use %<enum%> keyword to refer to the type",