clang-format: Better understand Lambda poarameters.
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
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 7e794a3..733f70d 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -96,8 +96,15 @@
}
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;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 16471b7..6a2d0d8 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -3933,6 +3933,7 @@
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;");