From 344b6ca4d1b264b8bc2abf5eb91b52713d663a9d Mon Sep 17 00:00:00 2001 From: Volodymyr Sapsai Date: Tue, 10 Apr 2018 18:29:47 +0000 Subject: [PATCH] [Parser] Fix assertion-on-invalid for unexpected typename. In `ParseDeclarationSpecifiers` for the code class A typename A; we were able to annotate token `kw_typename` because it refers to existing type. But later during processing token `annot_typename` we failed to `SetTypeSpecType` and exited switch statement leaving annotation token unconsumed. The code after the switch statement failed because it didn't expect a special token. The fix is not to assume that switch statement consumes all special tokens and consume any token, not just non-special. rdar://problem/37099386 Reviewers: rsmith, arphaman Reviewed By: rsmith Subscribers: jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D44449 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329735 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 3 ++- test/Parser/cxx-decl.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 8ce4c9aa2e..f17212d9b3 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3804,7 +3804,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, DS.SetRangeEnd(Tok.getLocation()); if (DiagID != diag::err_bool_redeclaration) - ConsumeToken(); + // After an error the next token can be an annotation token. + ConsumeAnyToken(); AttrsLastTime = false; } diff --git a/test/Parser/cxx-decl.cpp b/test/Parser/cxx-decl.cpp index 1a24520b8f..e1b36ecfa9 100644 --- a/test/Parser/cxx-decl.cpp +++ b/test/Parser/cxx-decl.cpp @@ -298,6 +298,11 @@ inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}} } } +namespace rdar37099386 { + class A typename A; // expected-error {{expected a qualified name after 'typename'}} + // expected-error@-1 {{cannot combine with previous 'class' declaration specifier}} +} + // PR8380 extern "" // expected-error {{unknown linkage language}} test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} -- 2.40.0