From ab058aa6eb834f72e439f4b151775511a4250ae9 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 11 Mar 2014 09:59:36 +0000 Subject: [PATCH] clang-format: Fix incorrect lambda recognition exposed by r203452. Before: int i = a[a][a] -> f(); After: int i = a[a][a]->f(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203556 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 3 ++- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 6930bd22bc..ed72acf613 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -758,7 +758,8 @@ bool UnwrappedLineParser::tryToParseLambda() { // FIXME: This is a dirty way to access the previous token. Find a better // solution. if (!Line->Tokens.empty() && - (Line->Tokens.back().Tok->isOneOf(tok::identifier, tok::kw_operator) || + (Line->Tokens.back().Tok->isOneOf(tok::identifier, tok::kw_operator, + tok::r_square) || Line->Tokens.back().Tok->isSimpleTypeSpecifier())) { nextToken(); return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d3ad9fb5d3..75dc57d4e7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7980,6 +7980,7 @@ TEST_F(FormatTest, FormatsLambdas) { verifyFormat("double &operator[](int i) { return 0; }\n" "int i;"); verifyFormat("std::unique_ptr foo() {}"); + verifyFormat("int i = a[a][a]->f();"); // Other corner cases. verifyFormat("void f() {\n" -- 2.40.0