Skip to content

Commit 55f1b91

Browse files
authored
[Clang] Fix a crash when parsing an invalid decltype (#148798)
We would try to exact an annotated token before checking if it was valid, leading to a crash when `decltype` was the only token that was parsed (which can happen in the absense of opening paren) Fixes #114815
1 parent be4d754 commit 55f1b91

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,13 +1133,6 @@ void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
11331133
// make sure we have a token we can turn into an annotation token
11341134
if (PP.isBacktrackEnabled()) {
11351135
PP.RevertCachedTokens(1);
1136-
if (DS.getTypeSpecType() == TST_error) {
1137-
// We encountered an error in parsing 'decltype(...)' so lets annotate all
1138-
// the tokens in the backtracking cache - that we likely had to skip over
1139-
// to get to a token that allows us to resume parsing, such as a
1140-
// semi-colon.
1141-
EndLoc = PP.getLastCachedTokenLocation();
1142-
}
11431136
} else
11441137
PP.EnterToken(Tok, /*IsReinject*/ true);
11451138

clang/test/Parser/gh114815.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -verify %s -std=c++11 -fsyntax-only
2+
3+
#define ID(X) X
4+
extern int ID(decltype);
5+
// expected-error@-1 {{expected '(' after 'decltype'}} \
6+
// expected-error@-1 {{expected unqualified-id}}

0 commit comments

Comments
 (0)