[PATCH] D21187: Allow use of lambda expressions in array bounds

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 9 13:37:43 PDT 2016


rsmith added a subscriber: rsmith.

================
Comment at: lib/Sema/SemaExpr.cpp:12825
@@ -12824,1 +12824,3 @@
+      // BlockContext.
+      } else if (!Rec.IsArrayBound) {
         // C++1y [expr.const]p2:
----------------
This isn't correct; you still need to produce the diagnostic even if we're in an array bound, but it should be an `ExtWarn` controlled by `-Wvla`. A case like

    void f() {
      int arr[ true ? 1 : []{return 0}() ];
    }

is ill-formed in standard C++, but as we can evaluate the array bound as a constant, Clang will no longer diagnose it with this change in place.

================
Comment at: lib/Sema/SemaExpr.cpp:12834-12839
@@ -12832,8 +12833,8 @@
     } else {
       // Mark the capture expressions odr-used. This was deferred
       // during lambda expression creation.
       for (auto *Lambda : Rec.Lambdas) {
         for (auto *C : Lambda->capture_inits())
           MarkDeclarationsReferencedInExpr(C);
       }
     }
----------------
If you accept lambdas inside VLA bounds, you need to do this step for them.

================
Comment at: lib/Sema/SemaExpr.cpp:12848-12853
@@ -12846,8 +12847,8 @@
   if (Rec.isUnevaluated() || Rec.Context == ConstantEvaluated) {
     ExprCleanupObjects.erase(ExprCleanupObjects.begin() + Rec.NumCleanupObjects,
                              ExprCleanupObjects.end());
     ExprNeedsCleanups = Rec.ParentNeedsCleanups;
     CleanupVarDeclMarking();
     std::swap(MaybeODRUseExprs, Rec.SavedMaybeODRUseExprs);
   // Otherwise, merge the contexts together.
   } else {
----------------
This also looks wrong for your lambda-in-VLA-bound case.

Perhaps the best thing to do is to check whether we have a VLA *before* we pop the ExpressionEvaluationContextRecord, and if so, convert the context from ConstantEvaluated to Evaluated.


http://reviews.llvm.org/D21187





More information about the cfe-commits mailing list