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.

llvm-svn: 150255
This commit is contained in:
Douglas Gregor 2012-02-10 16:48:36 +00:00
parent e67004e2f1
commit 01db64f0ac
2 changed files with 30 additions and 3 deletions

View File

@ -9345,9 +9345,6 @@ void Sema::PopExpressionEvaluationContext() {
ExprNeedsCleanups = Rec.ParentNeedsCleanups; ExprNeedsCleanups = Rec.ParentNeedsCleanups;
CleanupVarDeclMarking(); CleanupVarDeclMarking();
std::swap(MaybeODRUseExprs, Rec.SavedMaybeODRUseExprs); std::swap(MaybeODRUseExprs, Rec.SavedMaybeODRUseExprs);
if (Rec.Context == Unevaluated) {
}
// Otherwise, merge the contexts together. // Otherwise, merge the contexts together.
} else { } else {
ExprNeedsCleanups |= Rec.ParentNeedsCleanups; ExprNeedsCleanups |= Rec.ParentNeedsCleanups;

View 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}} [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;
};
};
}
};
}