[PATCH] Tune capturing of init-captures in non-generic lambdas

Faisal Vali faisalv at yahoo.com
Sat Nov 2 19:08:43 PDT 2013


  I should have been clearer in my initial post regarding what doesn't currently work in clang.

  clang croaks on the following:
    void test() {
      const int x = 10;
      auto L = [&j = x](int i) { };
    }

  We get the following error:
    - error: variable 'x' cannot be implicitly captured in a lambda with no capture-default specified

  The reason is that the init-capture's init-expr doesn't actually get analyzed for any lvalue-to-rvalue conversions during the initial parsing and creation of declrefexprs.  All declrefexprs of variables that do not involve constants, get appropriately tagged for odr-use and capture.  But for constants that might not be odr-used, this ends up happening later once the lambda's call operator has been pushed on the declcontext stack, and so 'x' is attempted to be captured by the lambda, which seems wrong.

  So the patch attempts to move up the creation of the init-var and analysis of the init-expr.

  Thanks!

http://llvm-reviews.chandlerc.com/D2092



More information about the cfe-commits mailing list