On Sat, Nov 2, 2013 at 1:51 PM, Richard Smith <[email protected]> wrote:
> > On 2 Nov 2013 10:33, "Faisal Vali" <[email protected]> wrote: > > > > Hi rsmith, doug.gregor, > > > > > > > > Currently clang does not seem to get capturing of init-captures > correctly. > > > > Consider the following code: > > void test() { > > const int x = 10; > > const int y = 12; > > auto L = [&k = x, j = x](int a) { > > return [&l = x, m = y] (int b) { }; > > This is ill formed, right? You can't odr-use x in the init of l. > > yes this is ill-formed only because the outer lambda does not have a default-capture (or explicitly captured 'x'). With the default-capture in the enclosing lambda, 'x' would be odr used, and so the outer lambda would have to capture it. Unless i am missing something? > > }; > > } > > > > The outer lambda needs to capture 'x' but not 'y'. And the inner lambda > should not capture either x or y. > > Neither should capture either, because there is no capture default. Should > the outer lambda have a default of & in your example? > > Yes - the outer lambda would need to capture 'x' - and the code as written would result in an error. > > This patch fixes this by: > > - 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) > > - 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). > > > > Tests added - and regressions tests all seem to pass. > > > > Certain aspects of this patch might emanate a bad smell - lets see if > anyone else feels the same ;) > > > > Thanks! > > > > http://llvm-reviews.chandlerc.com/D2092 > > > > Files: > > include/clang/AST/Decl.h > > include/clang/Sema/DeclSpec.h > > include/clang/Sema/Sema.h > > lib/AST/Decl.cpp > > lib/Parse/ParseExprCXX.cpp > > lib/Sema/Sema.cpp > > lib/Sema/SemaDecl.cpp > > lib/Sema/SemaLambda.cpp > > lib/Sema/SemaTemplateInstantiate.cpp > > lib/Sema/SemaTemplateVariadic.cpp > > lib/Sema/TreeTransform.h > > test/SemaCXX/cxx1y-init-captures.cpp >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
