]> granicus.if.org Git - clang/commitdiff
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.

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

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

index 7d54156c3bc0c79b810809fc371563e17d0e7e23..0c8d486f0eb0b9358b66770e41e54edb43120a0d 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 c91d378dd4a0d884455c4ff0134cf16719f07226..cd8326510668f8d44d8e80540a96639e13967248 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) {