From 363193b1bd4d9e0f07d361113157b9d4f229f212 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 20 Oct 2013 18:15:30 +0000 Subject: [PATCH] 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 --- lib/Format/TokenAnnotator.cpp | 9 ++++++++- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 7e794a3d2d..733f70d720 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 16471b754a..6a2d0d89b4 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3933,6 +3933,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("Type **A = static_cast(P);"); verifyGoogleFormat("Type** A = static_cast(P);"); verifyFormat("auto a = [](int **&, int ***) {};"); + verifyFormat("auto PointerBinding = [](const char *S) {};"); verifyFormat("typedef typeof(int(int, int)) *MyFunc;"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); -- 2.40.0