Skip to content

Commit 9d330c9

Browse files
committed
[clang-format] Fix crash in TokenAnnotator #82349
Squash commit from llvm/llvm-project#82349 Change-Id: Ie2a8d501486f2132e5ab9db57159a01f1b631fec Reviewed-by: Marcus Tillmanns <[email protected]>
1 parent 7c67fc2 commit 9d330c9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
33343334
do {
33353335
Tok = Tok->Next;
33363336
} while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
3337-
if (!Tok)
3337+
if (!Tok || !Tok->MatchingParen)
33383338
break;
33393339
const auto *LeftParen = Tok;
33403340
for (Tok = Tok->Next; Tok && Tok != LeftParen->MatchingParen;

clang/unittests/Format/FormatTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13332,6 +13332,12 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
1333213332
verifyFormat("{");
1333313333
verifyFormat("#})");
1333413334
verifyNoCrash("(/**/[:!] ?[).");
13335+
verifyNoCrash("struct X {\n"
13336+
" operator iunt(\n"
13337+
"};");
13338+
verifyNoCrash("struct Foo {\n"
13339+
" operator foo(bar\n"
13340+
"};");
1333513341
}
1333613342

1333713343
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {

0 commit comments

Comments
 (0)