Skip to content

Commit a72609c

Browse files
committed
[Format] Don't crash on mismatched brackets
1 parent 25ea6fa commit a72609c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
28372837
if (!Current.is(TT_StartOfName) || Current.NestingLevel != 0)
28382838
return false;
28392839
for (; Next; Next = Next->Next) {
2840-
if (Next->is(TT_TemplateOpener)) {
2840+
if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
28412841
Next = Next->MatchingParen;
28422842
} else if (Next->is(tok::coloncolon)) {
28432843
Next = Next->Next;

clang/unittests/Format/FormatTestCSharp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,5 +1600,9 @@ TEST_F(FormatTestCSharp, ShortFunctions) {
16001600
Style);
16011601
}
16021602

1603+
TEST_F(FormatTestCSharp, BrokenBrackets) {
1604+
EXPECT_NE("", format("int where b <")); // reduced from crasher
1605+
}
1606+
16031607
} // namespace format
16041608
} // end namespace clang

0 commit comments

Comments
 (0)