Skip to content

Commit 2d079b9

Browse files
owencatstellar
authored andcommitted
release/20.x: [clang-format] Fix a crash on formatting missing r_paren/r_brace (llvm#138230)
Backport 79210fe
1 parent 2cacf46 commit 2d079b9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,8 +1837,8 @@ void UnwrappedLineParser::parseStructuralElement(
18371837
nextToken();
18381838
if (FormatTok->is(tok::l_paren)) {
18391839
parseParens();
1840-
assert(FormatTok->Previous);
1841-
if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
1840+
if (FormatTok->Previous &&
1841+
FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
18421842
tok::l_paren)) {
18431843
Line->SeenDecltypeAuto = true;
18441844
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13962,6 +13962,8 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
1396213962
verifyNoCrash("struct Foo {\n"
1396313963
" operator foo(bar\n"
1396413964
"};");
13965+
verifyNoCrash("decltype( {\n"
13966+
" {");
1396513967
}
1396613968

1396713969
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {

0 commit comments

Comments
 (0)