clang-format: Fix template declaration line breaking with comment.

Before, clang-format would always insert a linebreak before the comment
in code like:
  template <typename T> // T can be A, B or C.
  struct S {};

llvm-svn: 192297
This commit is contained in:
Daniel Jasper 2013-10-09 15:06:17 +00:00
parent 76a3c33d41
commit d3e014d404
2 changed files with 5 additions and 1 deletions

View File

@ -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)) &&

View File

@ -3586,6 +3586,9 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
" template <typename> class Baaaaaaar>\n"
"struct C {};",
AlwaysBreak);
verifyFormat("template <typename T> // T can be A, B or C.\n"
"struct C {};",
AlwaysBreak);
}
TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {