@@ -382,10 +382,25 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
382
382
return !State.NoLineBreak && !CurrentState.NoLineBreak ;
383
383
}
384
384
385
+ bool isMatchingBraceOnSameLine (const FormatToken *Token) {
386
+ if (!Token->MatchingParen )
387
+ return false ;
388
+ const FormatToken *Matching = Token->MatchingParen ;
389
+ const FormatToken *Current = Token;
390
+ while (Current && Current != Matching) {
391
+ if (Current->NewlinesBefore > 0 )
392
+ return false ;
393
+ Current = Current->Previous ;
394
+ }
395
+ return true ;
396
+ }
397
+
385
398
bool ContinuationIndenter::mustBreak (const LineState &State) {
386
399
const FormatToken &Current = *State.NextToken ;
387
400
const FormatToken &Previous = *Current.Previous ;
388
401
const auto &CurrentState = State.Stack .back ();
402
+ if (Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose )
403
+ return !isMatchingBraceOnSameLine (State.NextToken );
389
404
if (Style.BraceWrapping .BeforeLambdaBody && Current.CanBreakBefore &&
390
405
Current.is (TT_LambdaLBrace) && Previous.isNot (TT_LineComment)) {
391
406
auto LambdaBodyLength = getLengthToMatchingParen (Current, State.Stack );
@@ -1370,6 +1385,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
1370
1385
State.Stack .size () > 1 ) {
1371
1386
return State.Stack [State.Stack .size () - 2 ].LastSpace ;
1372
1387
}
1388
+ if (Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose &&
1389
+ State.Stack .size () > 1 ) {
1390
+ return State.Stack [State.Stack .size () - 2 ].LastSpace ;
1391
+ }
1373
1392
if (NextNonComment->is (TT_TemplateString) && NextNonComment->closesScope ())
1374
1393
return State.Stack [State.Stack .size () - 2 ].LastSpace ;
1375
1394
// Field labels in a nested type should be aligned to the brace. For example
0 commit comments