From d56069854c3bfea6de41e9328dabb7d54f93aec8 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 17 Mar 2016 17:31:49 -0400
Subject: [PATCH 11/17] FIXME: consolidate missing struct hint

---
 gcc/c/c-parser.c                            | 61 ++++++++++++++---------------
 gcc/testsuite/gcc.dg/spellcheck-typenames.c | 33 ++--------------
 2 files changed, 34 insertions(+), 60 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 8ada238..22af084 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1659,46 +1659,45 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
 	 with some kind of hint.
 	 If the user forgot a "struct" etc, suggest inserting
 	 it.  Otherwise, attempt to look for misspellings.  */
-      tree hint = NULL_TREE;
-      if (!(tag_exists_p (RECORD_TYPE, name)
-	    || tag_exists_p (UNION_TYPE, name)
-	    || tag_exists_p (ENUMERAL_TYPE, name)))
+      rich_location richloc (line_table, here);
+      if (tag_exists_p (RECORD_TYPE, name))
 	{
-	  hint = lookup_name_fuzzy (name, true);
+	  /* This is not C++ with its implicit typedef.  */
+	  richloc.add_fixit_insert (here, "struct");
+	  error_at_rich_loc (&richloc,
+			     "unknown type name %qE;"
+			     " use %<struct%> keyword to refer to the type",
+			     name);
 	}
-      if (hint)
+      else if (tag_exists_p (UNION_TYPE, name))
 	{
-	  rich_location richloc (line_table, here);
-	  richloc.add_fixit_replace (get_range_from_loc (line_table, here),
-				     IDENTIFIER_POINTER (hint));
+	  richloc.add_fixit_insert (here, "union");
 	  error_at_rich_loc (&richloc,
-			     "unknown type name %qE; did you mean %qE?",
-			     name, hint);
+			     "unknown type name %qE;"
+			     " use %<union%> keyword to refer to the type",
+			     name);
+	}
+      else if (tag_exists_p (ENUMERAL_TYPE, name))
+	{
+	  richloc.add_fixit_insert (here, "enum");
+	  error_at_rich_loc (&richloc,
+			     "unknown type name %qE;"
+			     " use %<enum%> keyword to refer to the type",
+			     name);
 	}
       else
 	{
-	  error_at (here, "unknown type name %qE", name);
-	  /* Give a hint to the user.  This is not C++ with its implicit
-	     typedef.  */
-	  rich_location richloc (line_table, here);
-	  if (tag_exists_p (RECORD_TYPE, name))
+	  tree hint = lookup_name_fuzzy (name, true);
+	  if (hint)
 	    {
-	      richloc.add_fixit_insert (here, "struct");
-	      inform_at_rich_loc
-		(&richloc, "use %<struct%> keyword to refer to the type");
-	    }
-	  else if (tag_exists_p (UNION_TYPE, name))
-	    {
-	      richloc.add_fixit_insert (here, "union");
-	      inform_at_rich_loc
-		(&richloc, "use %<union%> keyword to refer to the type");
-	    }
-	  else if (tag_exists_p (ENUMERAL_TYPE, name))
-	    {
-	      richloc.add_fixit_insert (here, "enum");
-	      inform_at_rich_loc
-		(&richloc, "use %<enum%> keyword to refer to the type");
+	      richloc.add_fixit_replace (get_range_from_loc (line_table, here),
+					 IDENTIFIER_POINTER (hint));
+	      error_at_rich_loc (&richloc,
+				 "unknown type name %qE; did you mean %qE?",
+				 name, hint);
 	    }
+	  else
+	    error_at (here, "unknown type name %qE", name);
 	}
 
       /* Parse declspecs normally to get a correct pointer type, but avoid
diff --git a/gcc/testsuite/gcc.dg/spellcheck-typenames.c b/gcc/testsuite/gcc.dg/spellcheck-typenames.c
index 30d86fa..43146d8 100644
--- a/gcc/testsuite/gcc.dg/spellcheck-typenames.c
+++ b/gcc/testsuite/gcc.dg/spellcheck-typenames.c
@@ -20,19 +20,11 @@ nonsensical_suggestion_t var; /* { dg-bogus "did you mean" } */
 
 
 /* In the following, we should suggest inserting "struct" (rather
-   than "did you mean 'float'").  */
-
+   than "did you mean 'float'") and provide a fixit hint.  */
 struct foo_t {
   int i;
 };
-foo_t *foo_ptr; /* { dg-error "1: unknown type name .foo_t." } */
-/* { dg-begin-multiline-output "" }
- foo_t *foo_ptr;
- ^~~~~
-   { dg-end-multiline-output "" } */
-
-/* Verify that we get a fixit hint:  */
-/* { dg-message "1: use .struct. keyword to refer to the type" "" { target *-*-* } 28 } */
+foo_t *foo_ptr; /* { dg-error "1: unknown type name .foo_t.; use .struct. keyword to refer to the type" } */
 /* { dg-begin-multiline-output "" }
  foo_t *foo_ptr;
  ^~~~~
@@ -41,19 +33,11 @@ foo_t *foo_ptr; /* { dg-error "1: unknown type name .foo_t." } */
 
 
 /* Similarly for unions.  */
-
 union bar_t {
   int i;
   char j;
 };
-bar_t *bar_ptr; /* { dg-error "1: unknown type name .bar_t." } */
-/* { dg-begin-multiline-output "" }
- bar_t *bar_ptr;
- ^~~~~
-   { dg-end-multiline-output "" } */
-
-/* Verify that we get a fixit hint:  */
-/* { dg-message "1: use .union. keyword to refer to the type" "" { target *-*-* } 49 } */
+bar_t *bar_ptr; /* { dg-error "1: unknown type name .bar_t.; use .union. keyword to refer to the type" } */
 /* { dg-begin-multiline-output "" }
  bar_t *bar_ptr;
  ^~~~~
@@ -62,20 +46,11 @@ bar_t *bar_ptr; /* { dg-error "1: unknown type name .bar_t." } */
 
 
 /* Similarly for enums.  */
-
 enum baz {
   BAZ_FIRST,
   BAZ_SECOND
 };
-
-baz value; /* { dg-error "1: unknown type name .baz." } */
-/* { dg-begin-multiline-output "" }
- baz value;
- ^~~
-   { dg-end-multiline-output "" } */
-
-/* Verify that we get a fixit hint:  */
-/* { dg-message "1: use .enum. keyword to refer to the type" "" { target *-*-* } 71 } */
+baz value; /* { dg-error "1: unknown type name .baz.; use .enum. keyword to refer to the type" } */
 /* { dg-begin-multiline-output "" }
  baz value;
  ^~~
-- 
1.8.5.3

