diff options
author | David Malcolm <dmalcolm@redhat.com> | 2023-06-15 20:56:41 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-06-15 20:56:41 -0400 |
commit | 57446d1bc9757ee1fb030600d38fa9487231f2a4 (patch) | |
tree | 3504face4ffa1b943315f0e527181c65796b1d5a /gcc/c | |
parent | 7ff793415f55fa9a92f348fecb8c75ac8acc8b87 (diff) | |
download | gcc-57446d1bc9757ee1fb030600d38fa9487231f2a4.zip gcc-57446d1bc9757ee1fb030600d38fa9487231f2a4.tar.gz gcc-57446d1bc9757ee1fb030600d38fa9487231f2a4.tar.bz2 |
c: add name hints to c_parser_declspecs [PR107583]
PR c/107583 notes that we weren't issuing a hint for
struct foo {
time_t mytime; /* missing <time.h> include should trigger fixit */
};
in the C frontend.
The root cause is that one of the "unknown type name" diagnostics
was missing logic to emit hints, which this patch fixes.
gcc/c/ChangeLog:
PR c/107583
* c-parser.cc (c_parser_declspecs): Add hints to "unknown type
name" error.
gcc/testsuite/ChangeLog:
PR c/107583
* c-c++-common/spellcheck-pr107583.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/c-parser.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 61487cc..24a6eb6 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -3182,7 +3182,19 @@ c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, attrs_ok = true; if (kind == C_ID_ID) { - error_at (loc, "unknown type name %qE", value); + auto_diagnostic_group d; + name_hint hint = lookup_name_fuzzy (value, FUZZY_LOOKUP_TYPENAME, + loc); + if (const char *suggestion = hint.suggestion ()) + { + gcc_rich_location richloc (loc); + richloc.add_fixit_replace (suggestion); + error_at (&richloc, + "unknown type name %qE; did you mean %qs?", + value, suggestion); + } + else + error_at (loc, "unknown type name %qE", value); t.kind = ctsk_typedef; t.spec = error_mark_node; } |