]> granicus.if.org Git - clang/commitdiff
Add test from [expr.prim.lambda]p12, which deals with odr-use and
authorDouglas Gregor <dgregor@apple.com>
Fri, 10 Feb 2012 16:48:36 +0000 (16:48 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 10 Feb 2012 16:48:36 +0000 (16:48 +0000)
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.

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

lib/Sema/SemaExpr.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp

index fc7f32ec6d05ffec3400d1481f5d96eca0fbaf6a..7be1a441c46d1609e9be8ee2fe9dbb407d317175 100644 (file)
@@ -9345,9 +9345,6 @@ void Sema::PopExpressionEvaluationContext() {
     ExprNeedsCleanups = Rec.ParentNeedsCleanups;
     CleanupVarDeclMarking();
     std::swap(MaybeODRUseExprs, Rec.SavedMaybeODRUseExprs);
-
-    if (Rec.Context == Unevaluated) {
-    }
   // Otherwise, merge the contexts together.
   } else {
     ExprNeedsCleanups |= Rec.ParentNeedsCleanups;
index 5a696d76a5865fe5892d7e9e41f5a1c9458540f7..fdf6c53633dbf9175d13279a2a97e73f27dfa592 100644 (file)
@@ -46,3 +46,33 @@ void immediately_enclosing(int i) { // expected-note{{'i' declared here}}
     [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;
+        };
+      };
+    } 
+  };
+}