[PATCH] Tune capturing of init-captures in non-generic lambdas

Richard Smith richard at metafoo.co.uk
Wed Dec 4 10:40:32 PST 2013


  LGTM


================
Comment at: lib/Parse/ParseExprCXX.cpp:702-705
@@ -701,2 +701,6 @@
   typedef Optional<unsigned> DiagResult;
+  // Each lambda init-capture forms its own full expression, which clears
+  // Actions.MaybeODRUseExprs. So create an expression evaluation context to
+  // save the necessary state, and restore it later.
+  EnterExpressionEvaluationContext EC(Actions, Sema::PotentiallyEvaluated);
 
----------------
Push this down into the parsing of the init-capture below.

================
Comment at: lib/Sema/SemaLambda.cpp:639-640
@@ +638,4 @@
+    if (CXXDirectInit->getNumExprs() == 0) {
+      // It isn't possible to write this directly, but it is possible to
+      // end up in this situation with "x(some_pack...);"
+      Diag(CXXDirectInit->getLocStart(), diag::err_init_capture_no_expression)
----------------
It's possible to write this directly for a lambda; remove the comment?

================
Comment at: lib/Sema/SemaLambda.cpp:617
@@ +616,3 @@
+
+  const bool IsDirectInit = isa<ParenListExpr>(Init) || isa<InitListExpr>(Init);
+
----------------
Please move the (deleted) comment from below to here:

  // We do not need to distinguish between direct-list-initialization
  // and copy-list-initialization here, because we will always deduce
  [...]



================
Comment at: lib/Sema/SemaLambda.cpp:908-910
@@ -826,4 +907,5 @@
         ContainsUnexpandedParameterPack = true;
-
-      Var = checkInitCapture(C->Loc, C->Kind == LCK_ByRef,
-                             C->Id, C->Init.take());
+      // If the initializer expression is usable, but the InitCaptureType
+      // is not then an error has occured - so ignore the capture for now.
+      // for e.g., [n{0}] { }; <-- if no <initializer_list> is included.
+      if (C->InitCaptureType.get().isNull()) 
----------------
Add a FIXME here: we should create the init capture variable and mark it invalid in this case.


http://llvm-reviews.chandlerc.com/D2092



More information about the cfe-commits mailing list