aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-12-04 17:34:27 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2024-12-04 17:34:27 -0500
commit2576dd68a60b3f317f89c8c007d0eea63151a793 (patch)
tree5ef6bba82cfee72342364b752a6ded83c7c7dc30 /gcc
parent68aefc6988dc34d4b9a2194f9fb08bccfe7a076b (diff)
downloadgcc-2576dd68a60b3f317f89c8c007d0eea63151a793.zip
gcc-2576dd68a60b3f317f89c8c007d0eea63151a793.tar.gz
gcc-2576dd68a60b3f317f89c8c007d0eea63151a793.tar.bz2
c++: give suggestion on misspelled class name [PR116771]
gcc/cp/ChangeLog: PR c++/116771 * parser.cc (cp_parser_name_lookup_error): Provide suggestions for the case of complete failure where there is no scope. gcc/testsuite/ChangeLog: PR c++/116771 * g++.dg/spellcheck-pr116771.C: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/parser.cc16
-rw-r--r--gcc/testsuite/g++.dg/spellcheck-pr116771.C9
2 files changed, 24 insertions, 1 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 2995a11..80e14b1 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -3399,7 +3399,21 @@ cp_parser_name_lookup_error (cp_parser* parser,
error_at (location, "%<%T::%E%> has not been declared",
parser->object_scope, name);
else
- error_at (location, "%qE has not been declared", name);
+ {
+ auto_diagnostic_group d;
+ name_hint hint
+ = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME, location);
+ if (const char *suggestion = hint.suggestion ())
+ {
+ gcc_rich_location richloc (location);
+ richloc.add_fixit_replace (suggestion);
+ error_at (&richloc,
+ "%qE has not been declared; did you mean %qs?",
+ name, suggestion);
+ }
+ else
+ error_at (location, "%qE has not been declared", name);
+ }
}
else if (parser->scope && parser->scope != global_namespace)
{
diff --git a/gcc/testsuite/g++.dg/spellcheck-pr116771.C b/gcc/testsuite/g++.dg/spellcheck-pr116771.C
new file mode 100644
index 0000000..fd8bd6d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/spellcheck-pr116771.C
@@ -0,0 +1,9 @@
+class layout_printer
+{
+ void print_newline ();
+};
+
+void
+layout_pirnter::print_newline () // { dg-error "'layout_pirnter' has not been declared; did you mean 'layout_printer'" }
+{
+}