aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2025-06-29 12:41:34 -0700
committerGitHub <noreply@github.com>2025-06-29 12:41:34 -0700
commitfa058647fe3ad7834f9d99af7597b00990afc186 (patch)
tree3c4bfd07dec41f3d095813d9bb355db14c5c2a51 /clang/lib/Format
parenta3a60e03e2bf7b79683517584a9a7b3e4c8cd297 (diff)
downloadllvm-fa058647fe3ad7834f9d99af7597b00990afc186.zip
llvm-fa058647fe3ad7834f9d99af7597b00990afc186.tar.gz
llvm-fa058647fe3ad7834f9d99af7597b00990afc186.tar.bz2
[clang-format] Make EndsInComma in ContinuationIndenter consistent (#146256)
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index b474547..4010f7f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -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 =