[clang] Fix crash on broken parameter declarators

Differential Revision: https://reviews.llvm.org/D114609
This commit is contained in:
Kadir Cetinkaya 2021-11-25 20:11:46 +01:00
parent 40e7d4cd3b
commit d026f2f7c6
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
2 changed files with 11 additions and 7 deletions

View File

@ -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.

View File

@ -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 '('}}
};