]> granicus.if.org Git - clang/commitdiff
Fix incorrect line breaking before trailing block comments.
authorDaniel Jasper <djasper@google.com>
Thu, 6 Jun 2013 16:08:57 +0000 (16:08 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 6 Jun 2013 16:08:57 +0000 (16:08 +0000)
Before, clang-format would happily move a trailing block comment to a
new line, which normally changes the perceived binding of that comment.

E.g., it would move:
void f() { /* comment */
  ...
}
to:
void f() {
  /* comment */
  ...
}

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 71a1a28c85fda6be2ffda5178d9ed9b8adfe08f6..8b1382ed7c666a70fa023e1f9a25cb6154445e74 100644 (file)
@@ -1198,7 +1198,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
       Left.Previous->is(tok::kw___attribute))
     return false;
 
-  if (Right.Type == TT_LineComment)
+  if (Right.isTrailingComment())
     // We rely on MustBreakBefore being set correctly here as we should not
     // change the "binding" behavior of a comment.
     return false;
index 19f702f06a67eef2b16c97a5112e7fb26244b31a..f5204b45768631260b5b67607fb167f0720ababb 100644 (file)
@@ -767,6 +767,15 @@ TEST_F(FormatTest, UnderstandsMultiLineComments) {
       "  /* Leading comment for bb... */ bbbbbbbbbbbbbbbbbbbbbbbbb);",
       format("f(aaaaaaaaaaaaaaaaaaaaaaaaa    ,   \n"
              "/* Leading comment for bb... */   bbbbbbbbbbbbbbbbbbbbbbbbb);"));
+  EXPECT_EQ(
+      "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+      "    aaaaaaaaaaaaaaaaaa,\n"
+      "    aaaaaaaaaaaaaaaaaa) { /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaa */\n"
+      "}",
+      format("void      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+             "                      aaaaaaaaaaaaaaaaaa  ,\n"
+             "    aaaaaaaaaaaaaaaaaa) {   /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaa */\n"
+             "}"));
 
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackParameters = false;