[cfe-commits] r161604 - in /cfe/trunk: lib/Parse/ParseExprCXX.cpp test/Parser/cxx0x-lambda-expressions.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Aug 9 12:01:51 PDT 2012


Author: rsmith
Date: Thu Aug  9 14:01:51 2012
New Revision: 161604

URL: http://llvm.org/viewvc/llvm-project?rev=161604&view=rev
Log:
In 'delete []', the '[]' never starts a lambda. Update a FIXME with a standard reference and add a test.

Modified:
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=161604&r1=161603&r2=161604&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Thu Aug  9 14:01:51 2012
@@ -2403,10 +2403,14 @@
   // Array delete?
   bool ArrayDelete = false;
   if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) {
-    // FIXME: This could be the start of a lambda-expression. We should
-    // disambiguate this, but that will require arbitrary lookahead if
-    // the next token is '(':
-    //   delete [](int*){ /* ... */
+    // C++11 [expr.delete]p1:
+    //   Whenever the delete keyword is followed by empty square brackets, it
+    //   shall be interpreted as [array delete].
+    //   [Footnote: A lambda expression with a lambda-introducer that consists
+    //              of empty square brackets can follow the delete keyword if
+    //              the lambda expression is enclosed in parentheses.]
+    // FIXME: Produce a better diagnostic if the '[]' is unambiguously a
+    //        lambda-introducer.
     ArrayDelete = true;
     BalancedDelimiterTracker T(*this, tok::l_square);
 

Modified: cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp?rev=161604&r1=161603&r2=161604&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp Thu Aug  9 14:01:51 2012
@@ -40,4 +40,11 @@
     int a5[3] = { []{return 0;}() };
     int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}}
   }
+
+  void delete_lambda(int *p) {
+    delete [] p;
+    delete [] (int*) { new int }; // ok, compound-literal, not lambda
+    delete [] { return new int; } (); // expected-error{{expected expression}}
+    delete [&] { return new int; } (); // ok, lambda
+  }
 };





More information about the cfe-commits mailing list