Skip to content

Commit fa05864

Browse files
authored
[clang-format] Make EndsInComma in ContinuationIndenter consistent (#146256)
1 parent a3a60e0 commit fa05864

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,15 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
19291929
return;
19301930
}
19311931

1932+
const bool EndsInComma = [](const FormatToken *Tok) {
1933+
if (!Tok)
1934+
return false;
1935+
const auto *Prev = Tok->getPreviousNonComment();
1936+
if (!Prev)
1937+
return false;
1938+
return Prev->is(tok::comma);
1939+
}(Current.MatchingParen);
1940+
19321941
unsigned NewIndent;
19331942
unsigned LastSpace = CurrentState.LastSpace;
19341943
bool AvoidBinPacking;
@@ -1948,9 +1957,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
19481957
NewIndent = CurrentState.LastSpace + Style.ContinuationIndentWidth;
19491958
}
19501959
const FormatToken *NextNonComment = Current.getNextNonComment();
1951-
bool EndsInComma = Current.MatchingParen &&
1952-
Current.MatchingParen->Previous &&
1953-
Current.MatchingParen->Previous->is(tok::comma);
19541960
AvoidBinPacking = EndsInComma || Current.is(TT_DictLiteral) ||
19551961
Style.isProto() || !Style.BinPackArguments ||
19561962
(NextNonComment && NextNonComment->isOneOf(
@@ -1984,11 +1990,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
19841990
LastSpace = std::max(LastSpace, CurrentState.Indent);
19851991
}
19861992

1987-
bool EndsInComma =
1988-
Current.MatchingParen &&
1989-
Current.MatchingParen->getPreviousNonComment() &&
1990-
Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
1991-
19921993
// If ObjCBinPackProtocolList is unspecified, fall back to BinPackParameters
19931994
// for backwards compatibility.
19941995
bool ObjCBinPackProtocolList =

clang/unittests/Format/FormatTest.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27953,13 +27953,6 @@ TEST_F(FormatTest, AlignArrayOfStructuresLeftAlignmentNonSquare) {
2795327953
"};",
2795427954
Style);
2795527955
verifyFormat("void foo() {\n"
27956-
" auto thing = test{\n"
27957-
" {\n"
27958-
" {13}, {something}, // A\n"
27959-
" }\n"
27960-
" };\n"
27961-
"}",
27962-
"void foo() {\n"
2796327956
" auto thing = test{\n"
2796427957
" {\n"
2796527958
" {13},\n"
@@ -28017,13 +28010,6 @@ TEST_F(FormatTest, AlignArrayOfStructuresRightAlignmentNonSquare) {
2801728010
"};",
2801828011
Style);
2801928012
verifyFormat("void foo() {\n"
28020-
" auto thing = test{\n"
28021-
" {\n"
28022-
" {13}, {something}, // A\n"
28023-
" }\n"
28024-
" };\n"
28025-
"}",
28026-
"void foo() {\n"
2802728013
" auto thing = test{\n"
2802828014
" {\n"
2802928015
" {13},\n"

0 commit comments

Comments
 (0)