release/20.x: [clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)

Backport 79210feb2993ff9a79ef11f8a7016a527d4fcf22
This commit is contained in:
Owen Pan 2025-05-09 17:55:48 -07:00 committed by Tom Stellard
parent 2cacf46f35
commit 2d079b96a5
2 changed files with 4 additions and 2 deletions

View File

@ -1837,8 +1837,8 @@ void UnwrappedLineParser::parseStructuralElement(
nextToken();
if (FormatTok->is(tok::l_paren)) {
parseParens();
assert(FormatTok->Previous);
if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
if (FormatTok->Previous &&
FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
tok::l_paren)) {
Line->SeenDecltypeAuto = true;
}

View File

@ -13962,6 +13962,8 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
verifyNoCrash("struct Foo {\n"
" operator foo(bar\n"
"};");
verifyNoCrash("decltype( {\n"
" {");
}
TEST_F(FormatTest, IncorrectUnbalancedBracesInMacrosWithUnicode) {