auto obj = [ name = 1, a = [name = 1]{} ]{}; obj.a.name;
test.cc: In function ‘int main()’: test.cc:5:38: warning: already captured ‘name’ in lambda expression auto obj = [ name = 1, a = [name = 1]{} ]{}; ^ test.cc:7:9: error: ‘struct main()::<lambda()>’ has no member named ‘name’ obj.a.name;
Why would you ever do:
[x=1, y="foo"]{
// use x, y
}();
When you can just do: auto x = 1;
auto y = "foo";
// use x, y
?auto obj = [ x=1, y="foo" ]{}; obj.x; obj.y;
For every init-capture a non-static data member named by the identifier of the init-capture is declared in the closure type. This member is not a bit-field and not mutable. http://isocpp.org/files/papers/N3648.html
I've been told in ##C++ that the current C++14 draft says: `An init-capture behaves as if it declares and explicitly captures a variable of the form “auto init-capture ;” whose declarative region is the lambda-expression’s compound-statement`
This change would make the named member access non-conforming