From e49d0fcfc616dcd90b7478bdf89466503a033b12 Mon Sep 17 00:00:00 2001 From: morinmorin Date: Thu, 16 Sep 2021 23:29:54 +0900 Subject: [PATCH] c++: add spellcheck suggestions for typedef etc. [PR77565] 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 | 10 ++++++++++ gcc/testsuite/g++.dg/spellcheck-pr77565.C | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/g++.dg/spellcheck-pr77565.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8d60f40706b..40308d0d33f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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 index 00000000000..2257f7b699d --- /dev/null +++ b/gcc/testsuite/g++.dg/spellcheck-pr77565.C @@ -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'\\?" } +}; -- 2.31.1