diff options
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 9 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7e794a3d2d5..733f70d7208 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 16471b754a3..6a2d0d89b4c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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;"); |