Previously, this caused ExprConstant to assert while verifying the lambda is constexpr:
void f() { int x = 0; [=]() constexpr { return x; }; }
The problem is that ActOnFinishFunctionBody evaluated the lambda's body before BuildLambdaExpr finished the lambda class. This patch fixes the problem by moving that check to BuildLambdaExpr.
PR36054
Thanks for taking a look!
Erik
How about we add a comment here along the lines of: Do not attempt to create the variable-reference to closure data member map while 'constexpr' checking a lambda's function call operator (standard reference). Currently constpexpr checking is done right after the end of the function definition for the syntehsized call operator marked explicitly constexpr - which occurs prior to adding the captures map to the closure object. Alternatively we could have conditioned the check at the end of the function body to bypass lambda call operators and then invoke the constexpr check once the lambda is completely processed.
Between you and me, I'm a little torn about this approach - if you can make an argument to consider your approach over this one - i think i could be swayed (if i'm not already ;) - unless of course richard weighs in as a tie breaker.