diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 3714088306c8..560e65ea684d 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -178,7 +178,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { State.Stack.back().BreakBeforeParameter) return true; if ((Current.Type == TT_CtorInitializerColon || - (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0))) + (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 && + !Current.isTrailingComment()))) return true; if ((Current.Type == TT_StartOfName || Current.is(tok::kw_operator)) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4a51448f335f..10d7413d4227 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3586,6 +3586,9 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { " template class Baaaaaaar>\n" "struct C {};", AlwaysBreak); + verifyFormat("template // T can be A, B or C.\n" + "struct C {};", + AlwaysBreak); } TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {