aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorrmarker <37921131+rmarker@users.noreply.github.com>2024-02-20 09:02:06 +1030
committerGitHub <noreply@github.com>2024-02-19 14:32:06 -0800
commit22fc2cb15d9e9bfb84145c6891fb748e8e52757e (patch)
tree5f32f2ed59f570cc9dccac59bfba7fa6394dac26 /clang/lib/Format/ContinuationIndenter.cpp
parent44b17679e354d2f23b8843589629573b3900119f (diff)
downloadllvm-22fc2cb15d9e9bfb84145c6891fb748e8e52757e.zip
llvm-22fc2cb15d9e9bfb84145c6891fb748e8e52757e.tar.gz
llvm-22fc2cb15d9e9bfb84145c6891fb748e8e52757e.tar.bz2
[clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (#81848)
Fix an issue where the lambda body left brace could sometimes fail to be wrapped when AllowShortLambdasOnASingleLine is enabled. Now, when BraceWrapping.BeforeLambdaBody is enabled, if the brace is not wrapped, we prevent breaks in the lambda body. Resolves #81845
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 97500ee..df44e69 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1803,7 +1803,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
}
if (Current.MatchingParen && Current.is(BK_Block)) {
- moveStateToNewBlock(State);
+ moveStateToNewBlock(State, Newline);
return;
}
@@ -1991,7 +1991,7 @@ void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
}
}
-void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
+void ContinuationIndenter::moveStateToNewBlock(LineState &State, bool NewLine) {
if (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
State.NextToken->is(TT_LambdaLBrace) &&
!State.Line->MightBeFunctionDecl) {
@@ -2003,10 +2003,18 @@ void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
NestedBlockIndent + (State.NextToken->is(TT_ObjCBlockLBrace)
? Style.ObjCBlockIndentWidth
: Style.IndentWidth);
+
+ // Even when wrapping before lambda body, the left brace can still be added to
+ // the same line. This occurs when checking whether the whole lambda body can
+ // go on a single line. In this case we have to make sure there are no line
+ // breaks in the body, otherwise we could just end up with a regular lambda
+ // body without the brace wrapped.
+ bool NoLineBreak = Style.BraceWrapping.BeforeLambdaBody && !NewLine &&
+ State.NextToken->is(TT_LambdaLBrace);
+
State.Stack.push_back(ParenState(State.NextToken, NewIndent,
State.Stack.back().LastSpace,
- /*AvoidBinPacking=*/true,
- /*NoLineBreak=*/false));
+ /*AvoidBinPacking=*/true, NoLineBreak));
State.Stack.back().NestedBlockIndent = NestedBlockIndent;
State.Stack.back().BreakBeforeParameter = true;
}