Index: include/clang/AST/DataRecursiveASTVisitor.h =================================================================== --- include/clang/AST/DataRecursiveASTVisitor.h +++ include/clang/AST/DataRecursiveASTVisitor.h @@ -791,7 +791,7 @@ bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C) { - if (C->isInitCapture()) + if (LE->isInitCapture(C)) TRY_TO(TraverseDecl(C->getCapturedVar())); return true; } Index: include/clang/AST/ExprCXX.h =================================================================== --- include/clang/AST/ExprCXX.h +++ include/clang/AST/ExprCXX.h @@ -1559,7 +1559,10 @@ /// \brief Whether this lambda had its result type explicitly specified. bool hasExplicitResultType() const { return ExplicitResultType; } - + + // \brief Determine whether a given capture is an init-capture. + bool isInitCapture(const LambdaCapture* capture) const; + static bool classof(const Stmt *T) { return T->getStmtClass() == LambdaExprClass; } Index: include/clang/AST/RecursiveASTVisitor.h =================================================================== --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -857,7 +857,7 @@ bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C) { - if (C->isInitCapture()) + if (LE->isInitCapture(C)) TRY_TO(TraverseDecl(C->getCapturedVar())); return true; } Index: lib/AST/ExprCXX.cpp =================================================================== --- lib/AST/ExprCXX.cpp +++ lib/AST/ExprCXX.cpp @@ -1078,6 +1078,12 @@ IndexVars + IndexStarts[Index + 1]); } +bool LambdaExpr::isInitCapture(const LambdaCapture* capture) const { + return capture->capturesVariable() && + capture->getCapturedVar()->isInitCapture() && + getLambdaClass()->getDeclContext() == capture->getCapturedVar()->getDeclContext(); +} + CXXRecordDecl *LambdaExpr::getLambdaClass() const { return getType()->getAsCXXRecordDecl(); } Index: lib/AST/StmtPrinter.cpp =================================================================== --- lib/AST/StmtPrinter.cpp +++ lib/AST/StmtPrinter.cpp @@ -1758,7 +1758,7 @@ break; case LCK_ByRef: - if (Node->getCaptureDefault() != LCD_ByRef || C->isInitCapture()) + if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C)) OS << '&'; OS << C->getCapturedVar()->getName(); break; @@ -1770,7 +1770,7 @@ llvm_unreachable("VLA type in explicit captures."); } - if (C->isInitCapture()) + if (Node->isInitCapture(C)) PrintExpr(C->getCapturedVar()->getInit()); } OS << ']'; Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -9133,7 +9133,7 @@ for (LambdaExpr::capture_iterator C = E->capture_begin(), CEnd = E->capture_end(); C != CEnd; ++C) { - if (!C->isInitCapture()) + if (!E->isInitCapture(C)) continue; EnterExpressionEvaluationContext EEEC(getSema(), Sema::PotentiallyEvaluated); @@ -9245,7 +9245,7 @@ continue; // Rebuild init-captures, including the implied field declaration. - if (C->isInitCapture()) { + if (E->isInitCapture(C)) { InitCaptureInfoTy InitExprTypePair = InitCaptureExprsAndTypes[C - E->capture_begin()]; ExprResult Init = InitExprTypePair.first;