From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [pushed] c: add name hints to c_parser_declspecs [PR107583]
Date: Thu, 15 Jun 2023 21:01:38 -0400 [thread overview]
Message-ID: <20230616010138.1047991-1-dmalcolm@redhat.com> (raw)
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.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-1876-g57446d1bc9757e.
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.
---
gcc/c/c-parser.cc | 14 +++++++++++++-
gcc/testsuite/c-c++-common/spellcheck-pr107583.c | 10 ++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/c-c++-common/spellcheck-pr107583.c
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 5baa501dbee..f8b14e4c688 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;
}
diff --git a/gcc/testsuite/c-c++-common/spellcheck-pr107583.c b/gcc/testsuite/c-c++-common/spellcheck-pr107583.c
new file mode 100644
index 00000000000..86a9e7dbcb6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/spellcheck-pr107583.c
@@ -0,0 +1,10 @@
+struct s1 {
+ time_t mytime; /* { dg-error "unknown type name 'time_t'" "c error" { target c } } */
+ /* { dg-error "'time_t' does not name a type" "c++ error" { target c++ } .-1 } */
+ /* { dg-message "'time_t' is defined in header" "hint" { target *-*-* } .-2 } */
+};
+
+struct s2 {
+ unsinged i; /* { dg-error "unknown type name 'unsinged'; did you mean 'unsigned'." "c error" { target c } } */
+ /* { dg-error "'unsinged' does not name a type; did you mean 'unsigned'." "c++ error" { target c++ } .-1 } */
+};
--
2.26.3
reply other threads:[~2023-06-16 1:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230616010138.1047991-1-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).