clang-format: Fix false positive in lambda detection.
authorDaniel Jasper <djasper@google.com>
Sun, 2 Nov 2014 22:46:42 +0000 (22:46 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 2 Nov 2014 22:46:42 +0000 (22:46 +0000)
Before:
  delete [] a -> b;

After:
  delete[] a->b;

This fixes part of llvm.org/PR21419.

llvm-svn: 221114

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

index 7d54156..0c8d486 100644 (file)
@@ -849,7 +849,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::kw_new, tok::kw_delete) ||
        Line->Tokens.back().Tok->closesScope() ||
        Line->Tokens.back().Tok->isSimpleTypeSpecifier())) {
     nextToken();
index c91d378..cd83265 100644 (file)
@@ -4889,6 +4889,7 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
   verifyFormat("auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
                "    new (aaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa))\n"
                "        typename aaaaaaaaaaaaaaaaaaaaaaaa();");
+  verifyFormat("delete[] h->p;");
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {