Skip to content

Commit 7fb2d9f

Browse files
committed
[clang-format] Fix crashes due to missing l_paren
Fixes #54384. Differential Revision: https://reviews.llvm.org/D121682
1 parent bab468f commit 7fb2d9f

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,8 @@ class AnnotatingParser {
10231023
if (Style.isCpp() && CurrentToken && CurrentToken->is(tok::kw_co_await))
10241024
next();
10251025
Contexts.back().ColonIsForRangeExpr = true;
1026+
if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
1027+
return false;
10261028
next();
10271029
if (!parseParens())
10281030
return false;

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12113,6 +12113,7 @@ TEST_F(FormatTest, IncorrectCodeMissingParens) {
1211312113
verifyFormat("if {\n foo;\n foo();\n}");
1211412114
verifyFormat("switch {\n foo;\n foo();\n}");
1211512115
verifyIncompleteFormat("for {\n foo;\n foo();\n}");
12116+
verifyIncompleteFormat("ERROR: for target;");
1211612117
verifyFormat("while {\n foo;\n foo();\n}");
1211712118
verifyFormat("do {\n foo;\n foo();\n} while;");
1211812119
}

0 commit comments

Comments
 (0)