Skip to content

Commit 9f7b5cc

Browse files
committed
[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 llvm-svn: 329735
1 parent 4424285 commit 9f7b5cc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3804,7 +3804,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
38043804

38053805
DS.SetRangeEnd(Tok.getLocation());
38063806
if (DiagID != diag::err_bool_redeclaration)
3807-
ConsumeToken();
3807+
// After an error the next token can be an annotation token.
3808+
ConsumeAnyToken();
38083809

38093810
AttrsLastTime = false;
38103811
}

clang/test/Parser/cxx-decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}}
298298
}
299299
}
300300

301+
namespace rdar37099386 {
302+
class A typename A; // expected-error {{expected a qualified name after 'typename'}}
303+
// expected-error@-1 {{cannot combine with previous 'class' declaration specifier}}
304+
}
305+
301306
// PR8380
302307
extern "" // expected-error {{unknown linkage language}}
303308
test6a { ;// expected-error {{C++ requires a type specifier for all declarations}}

0 commit comments

Comments
 (0)