]> granicus.if.org Git - clang/commitdiff
clang-format: Fix another false positive in the lambda detection.
authorDaniel Jasper <djasper@google.com>
Tue, 11 Mar 2014 10:03:33 +0000 (10:03 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 11 Mar 2014 10:03:33 +0000 (10:03 +0000)
Before:
  int i = (*b)[a] -> f();

After:
  int i = (*b)[a]->f();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203557 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index ed72acf613b6e6bfb43b2c3b1109e3cf4f776dec..daf185be519e3307e0270c02e2318a628b7de6d8 100644 (file)
@@ -758,8 +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,
-                                        tok::r_square) ||
+      (Line->Tokens.back().Tok->isOneOf(tok::identifier, tok::kw_operator) ||
+       Line->Tokens.back().Tok->closesScope() ||
        Line->Tokens.back().Tok->isSimpleTypeSpecifier())) {
     nextToken();
     return false;
index 75dc57d4e798582451ae7ef2562ec44171124549..c6968bcef9e3b2a42dfbc86584d72aff7604c91b 100644 (file)
@@ -7981,6 +7981,7 @@ TEST_F(FormatTest, FormatsLambdas) {
                "int i;");
   verifyFormat("std::unique_ptr<int[]> foo() {}");
   verifyFormat("int i = a[a][a]->f();");
+  verifyFormat("int i = (*b)[a]->f();");
 
   // Other corner cases.
   verifyFormat("void f() {\n"