When first parsing a lambda expression, BuildDeclRefExpr is called on the parameter declarations with the lambda scope already pushed. But when transforming a lambda expression as part of instantiating an outer template, BuildDeclRefExpr is called again without the scope pushed. This causes tryCaptureVariable to get confused when a lambda parameter references an earlier parameter, e.g.:
[](auto c, int x = sizeof(decltype(c))) {}
Fix this by moving up the call to PushLambdaScope in TreeTransform::TransformLambdaExpr to match Parser::ParseLambdaExpressionAfterIntroducer.
(Note: I do not have commit access.)
Wouldn't it be better to keep the original C++11 test and add a second RUN: for the C++14 test?
Then guard the new test with #if __cplusplus >= 201402L