From d3c7ab975febc9fb0358a1c19c70fed9a8c83246 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(); llvm-svn: 203556 --- clang/lib/Format/UnwrappedLineParser.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 6930bd22bc97..ed72acf613b6 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d3ad9fb5d3b5..75dc57d4e798 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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"