Screenshot:
 https://dmalcolm.fedorapeople.org/gcc/2015-09-10/spellcheck-with-fixits.html

gcc/c/ChangeLog:
        * c-parser.c (c_parser_declaration_or_fndef): Add fix-it
        hint to "did you mean" suggestion.
        * c-typeck.c (build_component_ref): Likewise.

gcc/testsuite/ChangeLog:
        * gcc.dg/spellcheck.c: Update expected output to show fix-it
        hints.
---
 gcc/c/c-parser.c                  | 12 +++++++++---
 gcc/c/c-typeck.c                  |  3 +++
 gcc/testsuite/gcc.dg/spellcheck.c |  6 +++++-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index d134d85..1defa71 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1546,9 +1546,15 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
     {
       tree hint = lookup_name_fuzzy (c_parser_peek_token (parser)->value);
       if (hint)
-       error_at (here, "unknown type name %qE; did you mean %qE?",
-                 c_parser_peek_token (parser)->value,
-                 hint);
+       {
+         rich_location richloc (here);
+         richloc.add_fixit_replace (here,
+                                    IDENTIFIER_POINTER (hint));
+         error_at_rich_loc (&richloc,
+                            "unknown type name %qE; did you mean %qE?",
+                            c_parser_peek_token (parser)->value,
+                            hint);
+       }
       else
        error_at (here, "unknown type name %qE",
                  c_parser_peek_token (parser)->value);
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 507400b..0d92135 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2370,6 +2370,9 @@ build_component_ref (location_t loc, tree datum, tree 
component,
          field = lookup_field_fuzzy (type, component);
          if (field)
            {
+             richloc.add_fixit_replace
+               (*ident_range,
+                IDENTIFIER_POINTER (DECL_NAME (field)));
              error_at_rich_loc
                (&richloc,
                 "%qT has no member named %qE; did you mean %qE?",
diff --git a/gcc/testsuite/gcc.dg/spellcheck.c 
b/gcc/testsuite/gcc.dg/spellcheck.c
index e34ade8..892057e 100644
--- a/gcc/testsuite/gcc.dg/spellcheck.c
+++ b/gcc/testsuite/gcc.dg/spellcheck.c
@@ -15,6 +15,7 @@ int test (struct foo *ptr)
 /* { dg-begin-multiline-output "" }
    return ptr->m_bar;
           ~~~  ^~~~~
+               bar
    { dg-end-multiline-output "" } */
 }
 
@@ -26,11 +27,14 @@ int test2 (void)
 /* { dg-begin-multiline-output "" }
    return instance.m_bar;
           ~~~~~~~~ ^~~~~
+                   bar
    { dg-end-multiline-output "" } */
 }
 
-int64 foo; /* { dg-error "unknown type name 'int64'; did you mean 'int'?" } */
+#include <inttypes.h>
+int64 foo; /* { dg-error "unknown type name 'int64'; did you mean 'int64_t'?" 
} */
 /* { dg-begin-multiline-output "" }
  int64 foo;
  ^~~~~
+ int64_t
    { dg-end-multiline-output "" } */
-- 
1.8.5.3

Reply via email to