]> granicus.if.org Git - clang/commitdiff
clang-format: Better understand Lambda poarameters.
authorDaniel Jasper <djasper@google.com>
Sun, 20 Oct 2013 18:15:30 +0000 (18:15 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 20 Oct 2013 18:15:30 +0000 (18:15 +0000)
Before:
  auto PointerBinding = [](const char * S) {};

After:
  auto PointerBinding = [](const char *S) {};

This fixes llvm.org/PR17618.

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

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

index 7e794a3d2d546f1c47d3b236563852837033216e..733f70d72087935f040618f4eed66f6f257fcfc9 100644 (file)
@@ -96,8 +96,15 @@ private:
     }
 
     if (Left->Previous && Left->Previous->isOneOf(tok::kw_static_assert,
-                                                  tok::kw_if, tok::kw_while))
+                                                  tok::kw_if, tok::kw_while)) {
+      // static_assert, if and while usually contain expressions.
       Contexts.back().IsExpression = true;
+    } else if (Left->Previous && Left->Previous->is(tok::r_square) &&
+               Left->Previous->MatchingParen &&
+               Left->Previous->MatchingParen->Type == TT_LambdaLSquare) {
+      // This is a parameter list of a lambda expression.
+      Contexts.back().IsExpression = false;
+    }
 
     if (StartsObjCMethodExpr) {
       Contexts.back().ColonIsObjCMethodExpr = true;
index 16471b754a3da4ea027e6c5910d41cad14917a6b..6a2d0d89b4cdd61e6a4ae5996c054e0ead12bdb7 100644 (file)
@@ -3933,6 +3933,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("Type **A = static_cast<Type **>(P);");
   verifyGoogleFormat("Type** A = static_cast<Type**>(P);");
   verifyFormat("auto a = [](int **&, int ***) {};");
+  verifyFormat("auto PointerBinding = [](const char *S) {};");
   verifyFormat("typedef typeof(int(int, int)) *MyFunc;");
 
   verifyIndependentOfContext("InvalidRegions[*R] = 0;");