[cfe-commits] r150255 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp

Douglas Gregor dgregor at apple.com
Fri Feb 10 08:48:36 PST 2012


Author: dgregor
Date: Fri Feb 10 10:48:36 2012
New Revision: 150255

URL: http://llvm.org/viewvc/llvm-project?rev=150255&view=rev
Log:
Add test from [expr.prim.lambda]p12, which deals with odr-use and
nested captures. We currently don't get odr-use correct in array
bounds, so that bit is commented out while we sort out what we need to
do.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=150255&r1=150254&r2=150255&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb 10 10:48:36 2012
@@ -9345,9 +9345,6 @@
     ExprNeedsCleanups = Rec.ParentNeedsCleanups;
     CleanupVarDeclMarking();
     std::swap(MaybeODRUseExprs, Rec.SavedMaybeODRUseExprs);
-
-    if (Rec.Context == Unevaluated) {
-    }
   // Otherwise, merge the contexts together.
   } else {
     ExprNeedsCleanups |= Rec.ParentNeedsCleanups;

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp?rev=150255&r1=150254&r2=150255&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp Fri Feb 10 10:48:36 2012
@@ -46,3 +46,33 @@
     [i] {}(); // expected-error{{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
   }();
 }
+
+void f1(int i) { // expected-note{{declared here}}
+  int const N = 20;
+  auto m1 = [=]{
+    int const M = 30;
+    auto m2 = [i]{
+      // FIXME: We odr-use here, but we shouldn't.
+      //      int x[N][M];
+      //      x[0][0] = i;
+    }; 
+    (void)N;
+    (void)M;
+    (void)m2;
+  };
+  struct s1 {
+    int f;
+    void work(int n) { // expected-note{{declared here}}
+      int m = n*n;
+      int j = 40; // expected-note{{declared here}}
+      auto m3 = [this,m] { // expected-note 2{{lambda expression begins here}}
+        auto m4 = [&,j] { // expected-error{{variable 'j' cannot be implicitly captured in a lambda with no capture-default specified}}
+          int x = n; // expected-error{{variable 'n' cannot be implicitly captured in a lambda with no capture-default specified}}
+          x += m;
+          x += i; // expected-error{{reference to local variable 'i' declared in enclosing function 'f1'}}
+          x += f;
+        };
+      };
+    } 
+  };
+}





More information about the cfe-commits mailing list