From 26368c6ccd4d2f4b8d4b3bdd5f412338d22b3a28 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 8 May 2014 08:50:10 +0000 Subject: [PATCH] clang-format: Fix binary operator detection before lambdas. Before: bool foo = true&& [] { return false; }(); After: bool foo = true && [] { return false; }(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208288 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 2f8457c61b..2d94c7e6b2 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -904,7 +904,7 @@ private: PrevToken->Type == TT_UnaryOperator || PrevToken->Type == TT_CastRParen) return TT_UnaryOperator; - if (NextToken->is(tok::l_square)) + if (NextToken->is(tok::l_square) && NextToken->Type != TT_LambdaLSquare) return TT_PointerOrReference; if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1e9251d524..3ec1ea5084 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4612,6 +4612,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("void f(int *a = d * e, int *b = c * d);"); verifyFormat("for (char **a = b; *a; ++a) {\n}"); verifyFormat("for (; a && b;) {\n}"); + verifyFormat("bool foo = true && [] { return false; }();"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" -- 2.40.0