[clang-format] Make EndsInComma in ContinuationIndenter consistent (#146256)

This commit is contained in:
Owen Pan
2025-06-29 12:41:34 -07:00
committed by GitHub
parent a3a60e03e2
commit fa058647fe
2 changed files with 9 additions and 22 deletions

View File

@@ -1929,6 +1929,15 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
return;
}
const bool EndsInComma = [](const FormatToken *Tok) {
if (!Tok)
return false;
const auto *Prev = Tok->getPreviousNonComment();
if (!Prev)
return false;
return Prev->is(tok::comma);
}(Current.MatchingParen);
unsigned NewIndent;
unsigned LastSpace = CurrentState.LastSpace;
bool AvoidBinPacking;
@@ -1948,9 +1957,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
NewIndent = CurrentState.LastSpace + Style.ContinuationIndentWidth;
}
const FormatToken *NextNonComment = Current.getNextNonComment();
bool EndsInComma = Current.MatchingParen &&
Current.MatchingParen->Previous &&
Current.MatchingParen->Previous->is(tok::comma);
AvoidBinPacking = EndsInComma || Current.is(TT_DictLiteral) ||
Style.isProto() || !Style.BinPackArguments ||
(NextNonComment && NextNonComment->isOneOf(
@@ -1984,11 +1990,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
LastSpace = std::max(LastSpace, CurrentState.Indent);
}
bool EndsInComma =
Current.MatchingParen &&
Current.MatchingParen->getPreviousNonComment() &&
Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
// If ObjCBinPackProtocolList is unspecified, fall back to BinPackParameters
// for backwards compatibility.
bool ObjCBinPackProtocolList =

View File

@@ -27953,13 +27953,6 @@ TEST_F(FormatTest, AlignArrayOfStructuresLeftAlignmentNonSquare) {
"};",
Style);
verifyFormat("void foo() {\n"
" auto thing = test{\n"
" {\n"
" {13}, {something}, // A\n"
" }\n"
" };\n"
"}",
"void foo() {\n"
" auto thing = test{\n"
" {\n"
" {13},\n"
@@ -28017,13 +28010,6 @@ TEST_F(FormatTest, AlignArrayOfStructuresRightAlignmentNonSquare) {
"};",
Style);
verifyFormat("void foo() {\n"
" auto thing = test{\n"
" {\n"
" {13}, {something}, // A\n"
" }\n"
" };\n"
"}",
"void foo() {\n"
" auto thing = test{\n"
" {\n"
" {13},\n"