]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug where clang-format would break the code.
authorDaniel Jasper <djasper@google.com>
Wed, 9 Apr 2014 12:21:48 +0000 (12:21 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 9 Apr 2014 12:21:48 +0000 (12:21 +0000)
Before, it would turn:
  SomeFunction([]() { // Cool function..
    return 43;
  });

Into this:
  SomeFunction([]() { // Cool function.. return 43; });

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

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

index 5367106535d6590fb1de281d61445953605797cd..4075ccdc8cfdc2a8e4293552a59b5c14e01ad93f 100644 (file)
@@ -1121,6 +1121,10 @@ private:
     if (Previous.Children.size() > 1)
       return false;
 
+    // Cannot merge into one line if this line ends on a comment.
+    if (Previous.is(tok::comment))
+      return false;
+
     // We can't put the closing "}" on a line with a trailing comment.
     if (Previous.Children[0]->Last->isTrailingComment())
       return false;
index b932b274d7096b51314eac9877313ff1a9ef41d3..5f44c5bb2b5ae36769bdc9c23d1294f4157b2f23 100644 (file)
@@ -8161,6 +8161,9 @@ TEST_F(FormatTest, FormatsLambdas) {
                "        x.end(),   //\n"
                "        [&](int, int) { return 1; });\n"
                "}\n");
+  verifyFormat("SomeFunction([]() { // A cool function...\n"
+               "  return 43;\n"
+               "});");
 
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");