From 84a12e18d3c6006ddd6659cd73aea402ac9d595e Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 10 Mar 2014 15:06:25 +0000 Subject: [PATCH] clang-format: Add spaces between lambdas and comments. Before: void f() { bar([]() {}// Does not respect SpacesBeforeTrailingComments ); } After: void f() { bar([]() {} // Does not respect SpacesBeforeTrailingComments ); } This fixes llvm.org/PR19017. llvm-svn: 203466 --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7efeaffc78db..bb91fa7f52c8 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ad1ad04160d3..6e8e955dda57 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7980,6 +7980,12 @@ TEST_F(FormatTest, FormatsLambdas) { verifyFormat("double &operator[](int i) { return 0; }\n" "int i;"); verifyFormat("std::unique_ptr foo() {}"); + + // Other corner cases. + verifyFormat("void f() {\n" + " bar([]() {} // Did not respect SpacesBeforeTrailingComments\n" + " );\n" + "}"); } TEST_F(FormatTest, FormatsBlocks) {