From f02455e5ee45a96b32dee2f44f9f46e2546beb8e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 10 Feb 2012 09:26:04 +0000 Subject: Add various tests for captures and the reaching scope of the lambda expression. Implement C++11 [expr.prim.lambda]p12's requirement that capturing a variable will odr-use it. llvm-svn: 150237 --- clang/lib/Sema/SemaExpr.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'clang/lib') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ae5dc55825b..fc7f32ec6d0 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9624,8 +9624,12 @@ static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI, // to be re-"exported" from the lambda expression itself. S.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); + // C++ [expr.prim.labda]p12: + // An entity captured by a lambda-expression is odr-used (3.2) in + // the scope containing the lambda-expression. Expr *Ref = new (S.Context) DeclRefExpr(Var, Type.getNonReferenceType(), VK_LValue, Loc); + Var->setUsed(true); // When the field has array type, create index variables for each // dimension of the array. We use these index variables to subscript @@ -9999,7 +10003,7 @@ void Sema::MarkMemberReferenced(MemberExpr *E) { MarkExprReferenced(*this, E->getMemberLoc(), E->getMemberDecl(), E); } -/// \brief Perform marking for a reference to an aribitrary declaration. It +/// \brief Perform marking for a reference to an arbitrary declaration. It /// marks the declaration referenced, and performs odr-use checking for functions /// and variables. This method should not be used when building an normal /// expression which refers to a variable. -- cgit v1.2.3