<p dir="ltr"><br>
On 2 Nov 2013 10:33, "Faisal Vali" <<a href="mailto:faisalv@yahoo.com">faisalv@yahoo.com</a>> wrote:<br>
><br>
> Hi rsmith, doug.gregor,<br>
><br>
><br>
><br>
> Currently clang does not seem to get capturing of init-captures correctly.<br>
><br>
> Consider the following code:<br>
>     void test() {<br>
>        const int x = 10;<br>
>        const int y = 12;<br>
>        auto L = [&k = x, j = x](int a) {<br>
>            return [&l = x, m = y] (int b) { };</p>
<p dir="ltr">This is ill formed, right? You can't odr-use x in the init of l.</p>
<p dir="ltr">>        };<br>
>     }<br>
><br>
> The outer lambda needs to capture 'x' but not 'y'.  And the inner lambda should not capture either x or y.</p>
<p dir="ltr">Neither should capture either, because there is no capture default. Should the outer lambda have a default of & in your example?</p>
<p dir="ltr">> This patch fixes this by:<br>
>   - moving up the checking of the init capture before its lambda call operator's declcontext, scope, scopeinfo are pushed on (so that lvalue-to-rvalue conversions can be checked for const variables in the init-expr)<br>

>   - using the declcontext of the enclosing scope temporarily when the init-variable is created, and then fixing it once its call-operator has been created.  (this does require fixing the linkage computation of init-vars to return none, so that it isn't perceived as ever being declared at namespace scope).<br>

><br>
> Tests added - and regressions tests all seem to pass.<br>
><br>
> Certain aspects of this patch might emanate a bad smell - lets see if anyone else feels the same ;)<br>
><br>
> Thanks!<br>
><br>
> <a href="http://llvm-reviews.chandlerc.com/D2092">http://llvm-reviews.chandlerc.com/D2092</a><br>
><br>
> Files:<br>
>   include/clang/AST/Decl.h<br>
>   include/clang/Sema/DeclSpec.h<br>
>   include/clang/Sema/Sema.h<br>
>   lib/AST/Decl.cpp<br>
>   lib/Parse/ParseExprCXX.cpp<br>
>   lib/Sema/Sema.cpp<br>
>   lib/Sema/SemaDecl.cpp<br>
>   lib/Sema/SemaLambda.cpp<br>
>   lib/Sema/SemaTemplateInstantiate.cpp<br>
>   lib/Sema/SemaTemplateVariadic.cpp<br>
>   lib/Sema/TreeTransform.h<br>
>   test/SemaCXX/cxx1y-init-captures.cpp<br>
</p>