[clang] d026f2f - [clang] Fix crash on broken parameter declarators

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 26 02:03:55 PST 2021


Author: Kadir Cetinkaya
Date: 2021-11-26T10:56:54+01:00
New Revision: d026f2f7c688b326eae429286a06bf4080c8b527

URL: https://github.com/llvm/llvm-project/commit/d026f2f7c688b326eae429286a06bf4080c8b527
DIFF: https://github.com/llvm/llvm-project/commit/d026f2f7c688b326eae429286a06bf4080c8b527.diff

LOG: [clang] Fix crash on broken parameter declarators

Differential Revision: https://reviews.llvm.org/D114609

Added: 
    

Modified: 
    clang/lib/Parse/ParseDecl.cpp
    clang/test/Parser/cxx-keyword-identifiers.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a0871062395e..1bdeccc4cbf5 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6978,13 +6978,13 @@ void Parser::ParseParameterDeclarationClause(
       //
       // We care about case 1) where the declarator type should be known, and
       // the identifier should be null.
-      if (!ParmDeclarator.isInvalidType() && !ParmDeclarator.hasName()) {
-        if (Tok.getIdentifierInfo() &&
-            Tok.getIdentifierInfo()->isKeyword(getLangOpts())) {
-          Diag(Tok, diag::err_keyword_as_parameter) << PP.getSpelling(Tok);
-          // Consume the keyword.
-          ConsumeToken();
-        }
+      if (!ParmDeclarator.isInvalidType() && !ParmDeclarator.hasName() &&
+          Tok.isNot(tok::raw_identifier) && !Tok.isAnnotation() &&
+          Tok.getIdentifierInfo() &&
+          Tok.getIdentifierInfo()->isKeyword(getLangOpts())) {
+        Diag(Tok, diag::err_keyword_as_parameter) << PP.getSpelling(Tok);
+        // Consume the keyword.
+        ConsumeToken();
       }
       // Inform the actions module about the parameter declarator, so it gets
       // added to the current scope.

diff  --git a/clang/test/Parser/cxx-keyword-identifiers.cpp b/clang/test/Parser/cxx-keyword-identifiers.cpp
index 4a60ce9233f5..2c6f18ec83e0 100644
--- a/clang/test/Parser/cxx-keyword-identifiers.cpp
+++ b/clang/test/Parser/cxx-keyword-identifiers.cpp
@@ -25,3 +25,7 @@ void test() {
     int case; // expected-error {{expected member name or ';'}}
   };
 }
+struct Foo {
+  void bar(*decltype(1) aux); // expected-error {{C++ requires a type specifier for all declarations}}. \
+                                 // expected-error {{expected ')'}} expected-note {{to match this '('}}
+};


        


More information about the cfe-commits mailing list