From 7bf8f6fa8ab123fe97ccd82d9a0ddff85505ee5f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 4 Jun 2019 17:17:20 +0000 Subject: PR42104: Support instantiations of lambdas that implicitly capture packs. Two changes: * Track odr-use via FunctionParmPackExprs to properly handle dependent odr-uses of packs in generic lambdas. * Do not instantiate implicit captures; instead, regenerate them by instantiating the body of the lambda. This is necessary to distinguish between cases where only one element of a pack is captured and cases where the entire pack is captured. This reinstates r362358 (reverted in r362375) with a fix for an uninitialized variable use in UpdateMarkingForLValueToRValue. llvm-svn: 362531 --- clang/lib/Sema/SemaExprCXX.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'clang/lib/Sema/SemaExprCXX.cpp') diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index ac050fa1ef5..5884cf906fd 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -7427,12 +7427,7 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures( // All the potentially captureable variables in the current nested // lambda (within a generic outer lambda), must be captured by an // outer lambda that is enclosed within a non-dependent context. - const unsigned NumPotentialCaptures = - CurrentLSI->getNumPotentialVariableCaptures(); - for (unsigned I = 0; I != NumPotentialCaptures; ++I) { - Expr *VarExpr = nullptr; - VarDecl *Var = nullptr; - CurrentLSI->getPotentialVariableCapture(I, Var, VarExpr); + CurrentLSI->visitPotentialCaptures([&] (VarDecl *Var, Expr *VarExpr) { // If the variable is clearly identified as non-odr-used and the full // expression is not instantiation dependent, only then do we not // need to check enclosing lambda's for speculative captures. @@ -7446,7 +7441,7 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures( // } if (CurrentLSI->isVariableExprMarkedAsNonODRUsed(VarExpr) && !IsFullExprInstantiationDependent) - continue; + return; // If we have a capture-capable lambda for the variable, go ahead and // capture the variable in that lambda (and all its enclosing lambdas). @@ -7478,7 +7473,7 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures( DeclRefType, nullptr); } } - } + }); // Check if 'this' needs to be captured. if (CurrentLSI->hasPotentialThisCapture()) { -- cgit v1.2.3