Skip to content

Commit dcbbe24

Browse files
committed
[clang-format] Fix crash in TokenAnnotator #82349
Squash commit from llvm/llvm-project#82349 Change-Id: Ie2a8d501486f2132e5ab9db57159a01f1b631fec
1 parent 73b36bb commit dcbbe24

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
@@ -13422,6 +13422,12 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
1342213422
verifyFormat("{");
1342313423
verifyFormat("#})");
1342413424
verifyNoCrash("(/**/[:!] ?[).");
13425+
verifyNoCrash("struct X {\n"
13426+
" operator iunt(\n"
13427+
"};");
13428+
verifyNoCrash("struct Foo {\n"
13429+
" operator foo(bar\n"
13430+
"};");
1342513431
}
1342613432

1342713433
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {

0 commit comments

Comments
 (0)