@@ -382,10 +382,25 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
382382 return !State.NoLineBreak && !CurrentState.NoLineBreak ;
383383}
384384
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+
385398bool ContinuationIndenter::mustBreak (const LineState &State) {
386399 const FormatToken &Current = *State.NextToken ;
387400 const FormatToken &Previous = *Current.Previous ;
388401 const auto &CurrentState = State.Stack .back ();
402+ if (Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose )
403+ return !isMatchingBraceOnSameLine (State.NextToken );
389404 if (Style.BraceWrapping .BeforeLambdaBody && Current.CanBreakBefore &&
390405 Current.is (TT_LambdaLBrace) && Previous.isNot (TT_LineComment)) {
391406 auto LambdaBodyLength = getLengthToMatchingParen (Current, State.Stack );
@@ -1370,6 +1385,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
13701385 State.Stack .size () > 1 ) {
13711386 return State.Stack [State.Stack .size () - 2 ].LastSpace ;
13721387 }
1388+ if (Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose &&
1389+ State.Stack .size () > 1 ) {
1390+ return State.Stack [State.Stack .size () - 2 ].LastSpace ;
1391+ }
13731392 if (NextNonComment->is (TT_TemplateString) && NextNonComment->closesScope ())
13741393 return State.Stack [State.Stack .size () - 2 ].LastSpace ;
13751394 // Field labels in a nested type should be aligned to the brace. For example
0 commit comments