]> granicus.if.org Git - clang/commitdiff
clang-format: Don't merge lines with comments.
authorDaniel Jasper <djasper@google.com>
Sun, 7 Dec 2014 16:44:49 +0000 (16:44 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 7 Dec 2014 16:44:49 +0000 (16:44 +0000)
Before:
  int f() { // comment return 42; }

After:
  int f() { // comment
    return 42;
  }

This fixes llvm.org/PR21769.

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

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

index cf8e5d32ae58180c1ab76d17506e6b4eeeb89d15..ebd12909e1c1ce8757d541c320e8e6f823cfbf92 100644 (file)
@@ -665,6 +665,9 @@ public:
     }
     if (I[1]->First->is(TT_FunctionLBrace) &&
         Style.BreakBeforeBraces != FormatStyle::BS_Attach) {
+      if (I[1]->Last->is(TT_LineComment))
+        return 0;
+
       // Check for Limit <= 2 to account for the " {".
       if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(TheLine)))
         return 0;
index cf2d8097f7b220377660dbdf4884e086162d8dd8..8664711aa0703fa9f1827bbb5959c8c9ff2d6050 100644 (file)
@@ -8372,6 +8372,11 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
                "  [object someMethod:@{ @\"a\" : @\"b\" }];\n"
                "}",
                AllmanBraceStyle);
+  verifyFormat("int f()\n"
+               "{ // comment\n"
+               "  return 42;\n"
+               "}",
+               AllmanBraceStyle);
 
   AllmanBraceStyle.ColumnLimit = 19;
   verifyFormat("void f() { int i; }", AllmanBraceStyle);