]> granicus.if.org Git - clang/commitdiff
clang-format: Add spaces between lambdas and comments.
authorDaniel Jasper <djasper@google.com>
Mon, 10 Mar 2014 15:06:25 +0000 (15:06 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 10 Mar 2014 15:06:25 +0000 (15:06 +0000)
Before:
  void f() {
    bar([]() {}// Does not respect SpacesBeforeTrailingComments
        );
  }

After:
  void f() {
    bar([]() {} // Does not respect SpacesBeforeTrailingComments
        );
  }

This fixes llvm.org/PR19017.

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

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

index 7efeaffc78db9875490bf3d9a04c13fadc59e52f..bb91fa7f52c87fcc9ef652ffec9eb9022bd71c9d 100644 (file)
@@ -1100,7 +1100,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
   bool InFunctionDecl = Line.MightBeFunctionDecl;
   while (Current != NULL) {
     if (Current->Type == TT_LineComment) {
-      if (Current->Previous->BlockKind == BK_BracedInit)
+      if (Current->Previous->BlockKind == BK_BracedInit &&
+          Current->Previous->opensScope())
         Current->SpacesRequiredBefore = Style.Cpp11BracedListStyle ? 0 : 1;
       else
         Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
index ad1ad04160d313cd4c3c9046792868ca1c762586..6e8e955dda57dbdb94d9ecb6db42e7270ab1eae6 100644 (file)
@@ -7980,6 +7980,12 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("double &operator[](int i) { return 0; }\n"
                "int i;");
   verifyFormat("std::unique_ptr<int[]> foo() {}");
+
+  // Other corner cases.
+  verifyFormat("void f() {\n"
+               "  bar([]() {} // Did not respect SpacesBeforeTrailingComments\n"
+               "      );\n"
+               "}");
 }
 
 TEST_F(FormatTest, FormatsBlocks) {