class LambdaScopeInfo
Declaration
class LambdaScopeInfo : public CapturingScopeInfo,
public InventedTemplateParameterInfo { /* full declaration omitted */ };
Description
Retains information about a function, method, or block that is currently being parsed.
Declared at: clang/include/clang/Sema/ScopeInfo.h:830
Inherits from: CapturingScopeInfo, InventedTemplateParameterInfo
Member Variables
- public clang::CXXRecordDecl* Lambda = nullptr
- The class that describes the lambda.
- public clang::CXXMethodDecl* CallOperator = nullptr
- The lambda's compiler-generated \c operator().
- public clang::SourceRange IntroducerRange
- Source range covering the lambda introducer [...].
- public clang::SourceLocation CaptureDefaultLoc
- Source location of the ' & ' or '=' specifying the default capture type, if any.
- public unsigned int NumExplicitCaptures = 0
- The number of captures in the \c Captures list that are explicit captures.
- public bool Mutable = false
- Whether this is a mutable lambda.
- public bool ExplicitParams = false
- Whether the (empty) parameter list is explicit.
- public clang::CleanupInfo Cleanup
- Whether any of the capture expressions requires cleanups.
- public bool ContainsUnexpandedParameterPack = false
- Whether the lambda contains an unexpanded parameter pack.
- public SmallVector<clang::NamedDecl*, 4> LocalPacks
- Packs introduced by this lambda, if any.
- public clang::SourceRange ExplicitTemplateParamsRange
- Source range covering the explicit template parameter list (if it exists).
- public clang::ExprResult RequiresClause
- The requires-clause immediately following the explicit template parameter list, if any. (Note that there may be another requires-clause included as part of the lambda-declarator.)
- public clang::TemplateParameterList* GLTemplateParameterList = nullptr
- If this is a generic lambda, and the template parameter list has been created (from the TemplateParams) then store a reference to it (cache it to avoid reconstructing it).
- public llvm::SmallVector<Expr*, 4> PotentiallyCapturingExprs
- Potentially capturable variables of a nested lambda that might need to be captured by the lambda are housed here. This is specifically useful for generic lambdas or lambdas within a potentially evaluated-if-used context. If an enclosing variable is named in an expression of a lambda nested within a generic lambda, we don't always know know whether the variable will truly be odr-used (i.e. need to be captured) by that nested lambda, until its instantiation. But we still need to capture it in the enclosing lambda if all intervening lambdas can capture the variable.
- public llvm::SmallSet<Expr*, 8> NonODRUsedCapturingExprs
- Contains all variable-referring-expressions that refer to local variables that are usable as constant expressions and do not involve an odr-use (they may still need to be captured if the enclosing full-expression is instantiation dependent).
- public llvm::DenseMap<unsigned int, SourceRange> ExplicitCaptureRanges
- A map of explicit capture indices to their introducer source ranges.
- public llvm::SmallVector<ShadowedOuterDecl, 4> ShadowingDecls
- public clang::SourceLocation PotentialThisCaptureLocation
Inherited from InventedTemplateParameterInfo:
Inherited from CapturingScopeInfo:
- public ImpCaptureStyle
- public CaptureMap
- public CXXThisCaptureIndex = 0
- public Captures
- public HasImplicitReturnType = false
- public ReturnType
Inherited from FunctionScopeInfo:
- public Kind
- public HasBranchProtectedScope
- public HasBranchIntoScope
- public HasIndirectGoto
- public HasMustTail
- public HasDroppedStmt
- public HasOMPDeclareReductionCombiner
- public HasFallthroughStmt
- public UsesFPIntrin
- public HasPotentialAvailabilityViolations
- public ObjCShouldCallSuper
- public ObjCIsDesignatedInit
- public ObjCWarnForNoDesignatedInitChain
- public ObjCIsSecondaryInit
- public ObjCWarnForNoInitDelegation
- public NeedsCoroutineSuspends
- public FirstCoroutineStmtKind
- public FirstCoroutineStmtLoc
- public FirstReturnLoc
- public FirstCXXOrObjCTryLoc
- public FirstTryType = Unknown
- public FirstSEHTryLoc
- public SwitchStack
- public Returns
- public CoroutinePromise = nullptr
- public CoroutineParameterMoves
- public CoroutineSuspends
- public CompoundScopes
- public Blocks
- public ByrefBlockVars
- public PossiblyUnreachableDiags
- public ModifiedNonNullParams
Method Overview
- public LambdaScopeInfo(clang::DiagnosticsEngine & Diag)
- public void addPotentialCapture(clang::Expr * VarExpr)
- public void addPotentialThisCapture(clang::SourceLocation Loc)
- public static bool classof(const clang::sema::FunctionScopeInfo * FSI)
- public void clearPotentialCaptures()
- public void finishedExplicitCaptures()
- public unsigned int getNumPotentialVariableCaptures() const
- public bool hasPotentialCaptures() const
- public bool hasPotentialThisCapture() const
- public bool isGenericLambda() const
- public bool isVariableExprMarkedAsNonODRUsed(clang::Expr * CapturingVarExpr) const
- public void markVariableExprAsNonODRUsed(clang::Expr * CapturingVarExpr)
- public void removePotentialCapture(clang::Expr * E)
- public void visitPotentialCaptures(llvm::function_ref<void (VarDecl *, Expr *)> Callback) const
Inherited from CapturingScopeInfo:
- public addCapture
- public addThisCapture
- public addVLATypeCapture
- public classof
- public getCXXThisCapture
- public getCapture
- public getCapture
- public isCXXThisCaptured
- public isCaptured
- public isVLATypeCaptured
Inherited from FunctionScopeInfo:
- public Clear
- public NeedsScopeChecking
- public addBlock
- public addByrefBlockVar
- public getFirstCoroutineStmtKeyword
- public getWeakObjectUses
- public hasInvalidCoroutineSuspends
- public hasUnrecoverableErrorOccurred
- public isCoroutine
- public isPlainFunction
- public markSafeWeakUse
- public recordUseOfWeak
- public recordUseOfWeak
- public setCoroutineSuspends
- public setFirstCoroutineStmt
- public setHasBranchIntoScope
- public setHasBranchProtectedScope
- public setHasCXXTry
- public setHasDroppedStmt
- public setHasFallthroughStmt
- public setHasIndirectGoto
- public setHasMustTail
- public setHasOMPDeclareReductionCombiner
- public setHasObjCTry
- public setHasSEHTry
- public setNeedsCoroutineSuspends
- public setUsesFPIntrin
Methods
¶LambdaScopeInfo(clang::DiagnosticsEngine& Diag)
LambdaScopeInfo(clang::DiagnosticsEngine& Diag)
Declared at: clang/include/clang/Sema/ScopeInfo.h:913
Parameters
- clang::DiagnosticsEngine& Diag
¶void addPotentialCapture(clang::Expr* VarExpr)
void addPotentialCapture(clang::Expr* VarExpr)
Description
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas. This is also used by enclosing lambda's to speculatively capture variables that nested lambda's - depending on their enclosing specialization - might need to capture. Consider: void f(int, int); < -- don't capture void f(const int & , double); < -- capture void foo() { const int x = 10; auto L = [=](auto a) { // capture 'x' return [=](auto b) { f(x, a); // we may or may not need to capture 'x' }; }; }
Declared at: clang/include/clang/Sema/ScopeInfo.h:950
Parameters
- clang::Expr* VarExpr
¶void addPotentialThisCapture(
clang::SourceLocation Loc)
void addPotentialThisCapture(
clang::SourceLocation Loc)
Declared at: clang/include/clang/Sema/ScopeInfo.h:956
Parameters
¶static bool classof(
const clang::sema::FunctionScopeInfo* FSI)
static bool classof(
const clang::sema::FunctionScopeInfo* FSI)
Declared at: clang/include/clang/Sema/ScopeInfo.h:923
Parameters
- const clang::sema::FunctionScopeInfo* FSI
¶void clearPotentialCaptures()
void clearPotentialCaptures()
Declared at: clang/include/clang/Sema/ScopeInfo.h:1018
¶void finishedExplicitCaptures()
void finishedExplicitCaptures()
Description
Note when all explicit captures have been added.
Declared at: clang/include/clang/Sema/ScopeInfo.h:919
¶unsigned int getNumPotentialVariableCaptures()
const
unsigned int getNumPotentialVariableCaptures()
const
Declared at: clang/include/clang/Sema/ScopeInfo.h:1022
¶bool hasPotentialCaptures() const
bool hasPotentialCaptures() const
Declared at: clang/include/clang/Sema/ScopeInfo.h:1026
¶bool hasPotentialThisCapture() const
bool hasPotentialThisCapture() const
Declared at: clang/include/clang/Sema/ScopeInfo.h:960
¶bool isGenericLambda() const
bool isGenericLambda() const
Description
Is this scope known to be for a generic lambda? (This will be false until we parse a template parameter list or the first 'auto'-typed parameter).
Declared at: clang/include/clang/Sema/ScopeInfo.h:929
¶bool isVariableExprMarkedAsNonODRUsed(
clang::Expr* CapturingVarExpr) const
bool isVariableExprMarkedAsNonODRUsed(
clang::Expr* CapturingVarExpr) const
Declared at: clang/include/clang/Sema/ScopeInfo.h:1009
Parameters
- clang::Expr* CapturingVarExpr
¶void markVariableExprAsNonODRUsed(
clang::Expr* CapturingVarExpr)
void markVariableExprAsNonODRUsed(
clang::Expr* CapturingVarExpr)
Description
Mark a variable's reference in a lambda as non-odr using. For generic lambdas, if a variable is named in a potentially evaluated expression, where the enclosing full expression is dependent then we must capture the variable (given a default capture). This is accomplished by recording all references to variables (DeclRefExprs or MemberExprs) within said nested lambda in its array of PotentialCaptures. All such variables have to be captured by that lambda, except for as described below. If that variable is usable as a constant expression and is named in a manner that does not involve its odr-use (e.g. undergoes lvalue-to-rvalue conversion, or discarded) record that it is so. Upon the act of analyzing the enclosing full expression (ActOnFinishFullExpr) if we can determine that the full expression is not instantiation- dependent, then we can entirely avoid its capture. const int n = 0; [ & ] (auto x) { (void)+n + x; }; Interestingly, this strategy would involve a capture of n, even though it's obviously not odr-used here, because the full-expression is instantiation-dependent. It could be useful to avoid capturing such variables, even when they are referred to in an instantiation-dependent expression, if we can unambiguously determine that they shall never be odr-used. This would involve removal of the variable-referring-expression from the array of PotentialCaptures during the lvalue-to-rvalue conversions. But per the working draft N3797, (post-chicago 2013) we must capture such variables. Before anyone is tempted to implement a strategy for not-capturing 'n', consider the insightful warning in: /cfe-commits/Week-of-Mon-20131104/092596.html "The problem is that the set of captures for a lambda is part of the ABI (since lambda layout can be made visible through inline functions and the like), and there are no guarantees as to which cases we'll manage to build an lvalue-to-rvalue conversion in, when parsing a template -- some seemingly harmless change elsewhere in Sema could cause us to start or stop building such a node. So we need a rule that anyone can implement and get exactly the same result".
Declared at: clang/include/clang/Sema/ScopeInfo.h:1003
Parameters
- clang::Expr* CapturingVarExpr
¶void removePotentialCapture(clang::Expr* E)
void removePotentialCapture(clang::Expr* E)
Declared at: clang/include/clang/Sema/ScopeInfo.h:1015
Parameters
- clang::Expr* E
¶void visitPotentialCaptures(
llvm::function_ref<void(VarDecl*, Expr*)>
Callback) const
void visitPotentialCaptures(
llvm::function_ref<void(VarDecl*, Expr*)>
Callback) const
Declared at: clang/include/clang/Sema/ScopeInfo.h:1031
Parameters
- llvm::function_ref<void(VarDecl*, Expr*)> Callback