Skip to content

Commit 1a247aa

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 c84598b commit 1a247aa

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
@@ -3513,7 +3513,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
35133513
do {
35143514
Tok = Tok->Next;
35153515
} while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
3516-
if (!Tok)
3516+
if (!Tok || !Tok->MatchingParen)
35173517
break;
35183518
const auto *LeftParen = Tok;
35193519
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
@@ -13396,6 +13396,12 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
1339613396
verifyFormat("{");
1339713397
verifyFormat("#})");
1339813398
verifyNoCrash("(/**/[:!] ?[).");
13399+
verifyNoCrash("struct X {\n"
13400+
" operator iunt(\n"
13401+
"};");
13402+
verifyNoCrash("struct Foo {\n"
13403+
" operator foo(bar\n"
13404+
"};");
1339913405
}
1340013406

1340113407
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {

0 commit comments

Comments
 (0)