From: Douglas Gregor Date: Thu, 9 Feb 2012 02:12:34 +0000 (+0000) Subject: When we create a non-static data member in the closure object for a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20f87a4cd91b8d76571dc96aece916ac0bdf8b9f;p=clang When we create a non-static data member in the closure object for a capture, make sure we actually add the field. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150135 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 11468e8676..4db266b2ed 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9576,6 +9576,7 @@ static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI, 0, false, false); Field->setImplicit(true); Field->setAccess(AS_private); + Lambda->addDecl(Field); // C++11 [expr.prim.lambda]p21: // When the lambda-expression is evaluated, the entities that diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp index 4c876d7480..10d1e927bf 100644 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp +++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp @@ -29,3 +29,20 @@ void capture_with_default_args(CopyCtorDefault cct) { } // FIXME: arrays! + +// Check for the expected non-static data members. + +struct ExpectedLayout { + char a; + short b; +}; + +template void capture(const T&); + +void test_layout(char a, short b) { + auto x = [=] () -> void { // expected-error{{lambda expressions are not supported yet}} + capture(a); + capture(b); + }; + static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!"); +}