Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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 =
Expand Down
14 changes: 0 additions & 14 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading