]> granicus.if.org Git - clang/commitdiff
clang-format: Always add space before lambda-{
authorDaniel Jasper <djasper@google.com>
Fri, 12 Jun 2015 09:59:16 +0000 (09:59 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 12 Jun 2015 09:59:16 +0000 (09:59 +0000)
Before:
  int c = []() -> int *{ return 2; }();

After:
  int c = []() -> int * { return 2; }();

Based on patch by James Dennett (http://reviews.llvm.org/D10410), thank you!

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

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

index 3e8659ef853979938097b6f34ce3dae256e79323..8ffd67f0d11a6729220197486b4f1d1d9daf6216 100644 (file)
@@ -1800,6 +1800,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     return true;
   if (Left.is(TT_PointerOrReference))
     return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
+           (Right.is(tok::l_brace) && Right.BlockKind == BK_Block) ||
            (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
                            tok::l_paren) &&
             (Style.PointerAlignment != FormatStyle::PAS_Right &&
index e6df49d45906ef11748e69747a03cd5967d6ed31..f561475014abd5a33f91d4d497d559d414e9f9aa 100644 (file)
@@ -10098,6 +10098,7 @@ TEST_F(FormatTest, FormatsLambdas) {
 
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");
+  verifyFormat("int c = []() -> int * { return 2; }();\n");
   verifyFormat("int c = []() -> vector<int> { return {2}; }();\n");
   verifyFormat("Foo([]() -> std::vector<int> { return {2}; }());");
   verifyGoogleFormat("auto a = [&b, c](D* d) -> D* {};");