Skip to content

Commit 79210fe

Browse files
authored
[clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
Fix #138097
1 parent d3506ee commit 79210fe

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,8 @@ void UnwrappedLineParser::parseStructuralElement(
18341834
nextToken();
18351835
if (FormatTok->is(tok::l_paren)) {
18361836
parseParens();
1837-
assert(FormatTok->Previous);
1838-
if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
1837+
if (FormatTok->Previous &&
1838+
FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
18391839
tok::l_paren)) {
18401840
Line->SeenDecltypeAuto = true;
18411841
}

clang/unittests/Format/FormatTest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -14259,6 +14259,8 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
1425914259
verifyNoCrash("struct Foo {\n"
1426014260
" operator foo(bar\n"
1426114261
"};");
14262+
verifyNoCrash("decltype( {\n"
14263+
" {");
1426214264
}
1426314265

1426414266
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {

0 commit comments

Comments
 (0)