c++: add spellcheck suggestions for typedef etc. [PR77565]
authorMichel Morin <mimomorin@gmail.com>
Thu, 16 Sep 2021 14:29:54 +0000 (23:29 +0900)
committerJason Merrill <jason@redhat.com>
Thu, 23 Sep 2021 20:25:45 +0000 (16:25 -0400)
cp_keyword_starts_decl_specifier_p misses many keywords that can
start decl-specifiers. This patch adds support for those keywords.

PR c++/77565

gcc/cp/ChangeLog:

* parser.c (cp_keyword_starts_decl_specifier_p): Handle more
decl-specifiers (typedef/inline/cv/explicit/virtual/friend).

gcc/testsuite/ChangeLog:

* g++.dg/spellcheck-pr77565.C: New test.

gcc/cp/parser.c
gcc/testsuite/g++.dg/spellcheck-pr77565.C [new file with mode: 0644]

index 052fa25..1d1543d 100644 (file)
@@ -1051,6 +1051,16 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword)
     case RID_FLOAT:
     case RID_DOUBLE:
     case RID_VOID:
+      /* CV qualifiers.  */
+    case RID_CONST:
+    case RID_VOLATILE:
+      /* Function specifiers.  */
+    case RID_EXPLICIT:
+    case RID_VIRTUAL:
+      /* friend/typdef/inline specifiers.  */
+    case RID_FRIEND:
+    case RID_TYPEDEF:
+    case RID_INLINE:
       /* GNU extensions.  */
     case RID_ATTRIBUTE:
     case RID_TYPEOF:
diff --git a/gcc/testsuite/g++.dg/spellcheck-pr77565.C b/gcc/testsuite/g++.dg/spellcheck-pr77565.C
new file mode 100644 (file)
index 0000000..2257f7b
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+typdef int my_int; // { dg-error "1: 'typdef' does not name a type; did you mean 'typedef'\\?" }
+inlien int i_fn(); // { dg-error "1: 'inlien' does not name a type; did you mean 'inline'\\?" }
+coonst int ci = 1; // { dg-error "1: 'coonst' does not name a type; did you mean 'const'\\?" }
+voltil int vi = 2; // { dg-error "1: 'voltil' does not name a type; did you mean 'volatile'\\?" }
+
+class my_class {
+  explict my_class(int); // { dg-error "3: 'explict' does not name a type; did you mean 'explicit'\\?" }
+  friends double f_fn(); // { dg-error "3: 'friends' does not name a type; did you mean 'friend'\\?" }
+  virtial double v_fn(); // { dg-error "3: 'virtial' does not name a type; did you mean 'virtual'\\?" }
+};