Skip to content

[Clang] Fix a crash when parsing an invalid decltype #148798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,6 @@ void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
// make sure we have a token we can turn into an annotation token
if (PP.isBacktrackEnabled()) {
PP.RevertCachedTokens(1);
if (DS.getTypeSpecType() == TST_error) {
// We encountered an error in parsing 'decltype(...)' so lets annotate all
// the tokens in the backtracking cache - that we likely had to skip over
// to get to a token that allows us to resume parsing, such as a
// semi-colon.
EndLoc = PP.getLastCachedTokenLocation();
}
} else
PP.EnterToken(Tok, /*IsReinject*/ true);

Expand Down
6 changes: 6 additions & 0 deletions clang/test/Parser/gh114815.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 -verify %s -std=c++11 -fsyntax-only

#define ID(X) X
extern int ID(decltype);
// expected-error@-1 {{expected '(' after 'decltype'}} \
// expected-error@-1 {{expected unqualified-id}}