]> granicus.if.org Git - clang/commitdiff
clang-format: Fix template declaration line breaking with comment.
authorDaniel Jasper <djasper@google.com>
Wed, 9 Oct 2013 15:06:17 +0000 (15:06 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 9 Oct 2013 15:06:17 +0000 (15:06 +0000)
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 {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192297 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index 3714088306c8b6b87a0cb218bcdacade14423a5f..560e65ea684dd247f7453cf9d8a1107c0fcf1c77 100644 (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)) &&
index 4a51448f335f0a57bdec910b7308d1ec79ee12ae..10d7413d42271d34a965d243ba43c602b5c03a92 100644 (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) {