@@ -795,6 +795,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
795
795
// parenthesis by disallowing any further line breaks if there is no line
796
796
// break after the opening parenthesis. Don't break if it doesn't conserve
797
797
// columns.
798
+ auto IsOtherConditional = [](const FormatToken &Tok) {
799
+ return Tok.isOneOf (tok::kw_for, tok::kw_while, tok::kw_switch);
800
+ };
798
801
auto IsOpeningBracket = [&](const FormatToken &Tok) {
799
802
auto IsStartOfBracedList = [&]() {
800
803
return Tok.is (tok::l_brace) && Tok.isNot (BK_Block) &&
@@ -807,9 +810,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
807
810
if (!Tok.Previous )
808
811
return true ;
809
812
if (Tok.Previous ->isIf ())
810
- return Style .AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
811
- return !Tok.Previous ->isOneOf (TT_CastRParen, tok::kw_for, tok::kw_while,
812
- tok::kw_switch);
813
+ return Style .AlignAfterOpenBracketBreak .InIfConditionalStatements ;
814
+ if (IsOtherConditional (*Tok.Previous ))
815
+ return Style .AlignAfterOpenBracketBreak .InOtherConditionalStatements ;
816
+ return !Tok.Previous ->is (TT_CastRParen) &&
817
+ Style .AlignAfterOpenBracketBreak .Other ;
813
818
};
814
819
auto IsFunctionCallParen = [](const FormatToken &Tok) {
815
820
return Tok.is (tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
@@ -844,10 +849,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
844
849
Tok.isOneOf (tok::ellipsis, Keywords.kw_await ))) {
845
850
return true ;
846
851
}
847
- const auto *Previous = Tok.Previous ;
848
- if (!Previous || (!Previous->isOneOf (TT_FunctionDeclarationLParen,
849
- TT_LambdaDefinitionLParen) &&
850
- !IsFunctionCallParen (*Previous))) {
852
+ const auto *Previous = TokAfterLParen.Previous ;
853
+ assert (Previous); // IsOpeningBracket(Previous)
854
+ if (Previous->Previous && (Previous->Previous ->isIf () ||
855
+ IsOtherConditional (*Previous->Previous ))) {
856
+ return false ;
857
+ }
858
+ if (!Previous->isOneOf (TT_FunctionDeclarationLParen,
859
+ TT_LambdaDefinitionLParen) &&
860
+ !IsFunctionCallParen (*Previous)) {
851
861
return true ;
852
862
}
853
863
if (IsOpeningBracket (Tok) || IsInTemplateString (Tok))
@@ -1225,8 +1235,21 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
1225
1235
}
1226
1236
1227
1237
if (PreviousNonComment && PreviousNonComment->is (tok::l_paren)) {
1228
- CurrentState.BreakBeforeClosingParen =
1229
- Style .AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
1238
+ CurrentState.BreakBeforeClosingParen = false ;
1239
+ if (Style .AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
1240
+ auto Previous = PreviousNonComment->Previous ;
1241
+ if (Previous && Previous->isIf ()) {
1242
+ CurrentState.BreakBeforeClosingParen =
1243
+ Style .AlignAfterOpenBracketBreak .InIfConditionalStatements ;
1244
+ } else if (Previous && Previous->isOneOf (tok::kw_for, tok::kw_while,
1245
+ tok::kw_switch)) {
1246
+ CurrentState.BreakBeforeClosingParen =
1247
+ Style .AlignAfterOpenBracketBreak .InOtherConditionalStatements ;
1248
+ } else {
1249
+ CurrentState.BreakBeforeClosingParen =
1250
+ Style .AlignAfterOpenBracketBreak .Other ;
1251
+ }
1252
+ }
1230
1253
}
1231
1254
1232
1255
if (CurrentState.AvoidBinPacking ) {
0 commit comments