24 using namespace clang;
70 unsigned CurScopeIndex = FunctionScopes.size() - 1;
71 while (CurScopeIndex > 0 && isa<clang::sema::CapturedRegionScopeInfo>(
72 FunctionScopes[CurScopeIndex]))
75 isa<clang::sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]) &&
76 "The function on the top of sema's function-info stack must be a lambda");
79 const bool IsCapturingThis = !VarToCapture;
80 const bool IsCapturingVariable = !IsCapturingThis;
84 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex])->CallOperator;
88 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]);
96 if (IsCapturingVariable &&
98 return NoLambdaIsCaptureReady;
117 if (IsCapturingVariable && !LSI->
isCaptured(VarToCapture))
118 return NoLambdaIsCaptureReady;
120 return NoLambdaIsCaptureReady;
124 assert(CurScopeIndex);
130 assert(CurScopeIndex < (FunctionScopes.size() - 1));
134 return CurScopeIndex + 1;
135 return NoLambdaIsCaptureReady;
182 if (!OptionalStackIndex)
183 return NoLambdaIsCaptureCapable;
185 const unsigned IndexOfCaptureReadyLambda = OptionalStackIndex.getValue();
186 assert(((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) ||
188 "The capture ready lambda for a potential capture can only be the " 189 "current lambda if it is a generic lambda");
192 cast<sema::LambdaScopeInfo>(FunctionScopes[IndexOfCaptureReadyLambda]);
195 const bool IsCapturingThis = !VarToCapture;
196 const bool IsCapturingVariable = !IsCapturingThis;
198 if (IsCapturingVariable) {
203 const bool CanCaptureVariable =
209 DeclRefType, &IndexOfCaptureReadyLambda);
210 if (!CanCaptureVariable)
211 return NoLambdaIsCaptureCapable;
216 const bool CanCaptureThis =
220 &IndexOfCaptureReadyLambda);
222 return NoLambdaIsCaptureCapable;
224 return IndexOfCaptureReadyLambda;
270 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
282 Decl *&ManglingContextDecl) {
285 ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
299 if (ManglingContextDecl) {
300 if (
ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
303 if (LexicalDC->isRecord())
304 Kind = DefaultArgument;
305 }
else if (
VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
306 if (Var->getDeclContext()->isRecord())
307 Kind = StaticDataMember;
308 else if (Var->getMostRecentDecl()->isInline())
309 Kind = InlineVariable;
310 else if (Var->getDescribedVarTemplate())
311 Kind = VariableTemplate;
312 else if (
auto *VTS = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
313 if (!VTS->isExplicitSpecialization())
314 Kind = VariableTemplate;
316 }
else if (isa<FieldDecl>(ManglingContextDecl)) {
324 bool IsInNonspecializedTemplate =
325 inTemplateInstantiation() || CurContext->isDependentContext();
330 if ((IsInNonspecializedTemplate &&
331 !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
333 ManglingContextDecl =
nullptr;
334 while (
auto *CD = dyn_cast<CapturedDecl>(DC))
339 ManglingContextDecl =
nullptr;
343 case StaticDataMember:
345 if (!IsInNonspecializedTemplate) {
346 ManglingContextDecl =
nullptr;
354 case DefaultArgument:
358 case VariableTemplate:
360 return &ExprEvalContexts.back().getMangleNumberingContext(Context);
363 llvm_unreachable(
"unexpected context");
369 assert(ManglingContextDecl &&
"Need to have a context declaration");
370 if (!MangleNumbering)
372 return *MangleNumbering;
380 const bool IsConstexprSpecified) {
390 if (Result->isUndeducedType()) {
391 Result = SubstAutoType(Result, Context.
DependentTy);
414 MethodType, MethodTypeInfo,
417 IsConstexprSpecified,
430 if (TemplateMethod) {
437 if (!Params.empty()) {
439 CheckParmsForFunctionDef(Params,
443 P->setOwningFunction(Method);
446 Decl *ManglingContextDecl;
449 ManglingContextDecl)) {
450 unsigned ManglingNumber = MCtx->getManglingNumber(Method);
463 bool ExplicitResultType,
467 LSI->
Lambda = LambdaClass;
477 if (ExplicitResultType) {
483 diag::err_lambda_incomplete_result)) {
500 for (
unsigned p = 0, NumParams = CallOperator->
getNumParams();
501 p < NumParams; ++p) {
509 for (
const auto &
Capture : Captures) {
513 Diag(
Capture.Loc, diag::note_var_explicitly_captured_here)
518 CheckShadow(CurScope, Param);
520 PushOnScopeChains(Param, CurScope);
540 = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
541 return cast<EnumDecl>(D->getDeclContext());
549 if (BO->getOpcode() == BO_Comma)
556 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
557 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
578 if (ICE->getCastKind() == CK_IntegralCast)
586 return ET->getDecl();
609 if (!ED)
return nullptr;
612 for (++i; i != e; ++i) {
628 i = returns.begin(), e = returns.end(); i != e; ++i) {
640 Expr *E = (cleanups ? cleanups->getSubExpr() : retValue);
644 cleanups->setSubExpr(E);
655 assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().
CPlusPlus14) &&
656 "lambda expressions use auto deduction in C++14 onwards");
693 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
698 if (!getLangOpts().CPlusPlus) {
699 assert(isa<BlockScopeInfo>(CSI));
722 (RetE ? RetE->
getType() : Context.
VoidTy).getUnqualifiedType();
728 if (BlockNullability &&
729 (!RetTyNullability ||
738 diag::err_typecheck_missing_return_type_incompatible)
739 << ReturnType << CSI.
ReturnType << isa<LambdaScopeInfo>(CSI);
755 DeductType = BuildReferenceType(DeductType,
true, Loc, Id);
756 assert(!DeductType.
isNull() &&
"can't build reference to auto");
762 Expr *DeduceInit = Init;
770 bool CXXDirectInit = isa<ParenListExpr>(Init);
798 unsigned InitStyle,
Expr *Init) {
806 Loc, Id, InitCaptureType, TSI,
SC_Auto);
810 NewVD->
setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
836 bool KnownDependent =
false;
838 assert(LSI &&
"LambdaScopeInfo should be on stack!");
844 KnownDependent =
true;
848 bool ExplicitParams =
true;
849 bool ExplicitResultType =
true;
850 bool ContainsUnexpandedParameterPack =
false;
860 EPI.TypeQuals.addConst();
867 QualType DefaultTypeForNoTrailingReturn =
873 ExplicitParams =
false;
874 ExplicitResultType =
false;
878 "lambda-declarator is a function");
885 if (!FTI.hasMutableQualifier()) {
890 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
891 assert(MethodTyInfo &&
"no type from lambda-declarator");
894 ExplicitResultType = FTI.hasTrailingReturnType();
897 Params.reserve(FTI.NumParams);
898 for (
unsigned i = 0, e = FTI.NumParams; i != e; ++i)
899 Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
904 ContainsUnexpandedParameterPack =
true;
908 KnownDependent, Intro.
Default);
911 startLambdaDefinition(Class, Intro.
Range, MethodTyInfo, EndLoc, Params,
914 CheckCXXDefaultArguments(Method);
918 AddRangeBasedOptnone(Method);
921 if (
Attr *A = getImplicitCodeSegOrSectionAttrForFunction(Method,
true))
925 ProcessDeclAttributes(CurScope, Method, ParamInfo);
929 if (getLangOpts().CUDA)
930 CUDASetLambdaAttrs(Method);
933 PushDeclContext(CurScope, Method);
937 ExplicitParams, ExplicitResultType, !Method->
isConst());
951 (getCurrentThisType().isNull() ||
957 llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
963 PrevCaptureLoc = C->Loc, ++C) {
967 ? diag::ext_star_this_lambda_capture_cxx17
968 : diag::warn_cxx14_compat_star_this_lambda_capture);
974 Diag(C->Loc, diag::err_capture_more_than_once)
977 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
988 ? diag::ext_equals_this_lambda_capture_cxx2a
989 : diag::warn_cxx17_compat_equals_this_lambda_capture);
994 QualType ThisCaptureType = getCurrentThisType();
995 if (ThisCaptureType.
isNull()) {
996 Diag(C->Loc, diag::err_this_capture) <<
true;
1000 CheckCXXThisCapture(C->Loc,
true,
true,
1008 assert(C->Id &&
"missing identifier for capture");
1010 if (C->Init.isInvalid())
1014 if (C->Init.isUsable()) {
1016 ? diag::warn_cxx11_compat_init_capture
1017 : diag::ext_init_capture);
1019 if (C->Init.get()->containsUnexpandedParameterPack())
1020 ContainsUnexpandedParameterPack =
true;
1026 if (C->InitCaptureType.get().isNull())
1030 switch (C->InitKind) {
1032 llvm_unreachable(
"not an init-capture?");
1043 Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1044 C->Id, InitStyle, C->Init.get());
1050 PushOnScopeChains(Var, CurScope,
false);
1053 "init capture has valid but null init?");
1061 Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1063 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1066 Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1068 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1077 LookupName(R, CurScope);
1083 if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R,
1089 if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1096 if (!CaptureNames.insert(C->Id).second) {
1098 Diag(C->Loc, diag::err_capture_more_than_once)
1101 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1105 Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1114 Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1123 Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1131 if (C->EllipsisLoc.isValid()) {
1133 EllipsisLoc = C->EllipsisLoc;
1135 Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1141 ContainsUnexpandedParameterPack =
true;
1144 if (C->Init.isUsable()) {
1145 buildInitCaptureField(LSI, Var);
1148 TryCapture_ExplicitByVal;
1149 tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
1154 finishLambdaExplicitCaptures(LSI);
1159 addLambdaParameters(Intro.
Captures, Method, CurScope);
1163 PushExpressionEvaluationContext(
1164 ExpressionEvaluationContext::PotentiallyEvaluated);
1168 bool IsInstantiation) {
1172 DiscardCleanupsInEvaluationContext();
1173 PopExpressionEvaluationContext();
1176 if (!IsInstantiation)
1185 CheckCompletedCXXClass(Class);
1187 PopFunctionScopeInfo();
1203 "Lambda's call operator should not have a reference qualifier");
1216 auto HasPassObjectSizeAttr = [](
const ParmVarDecl *
P) {
1217 return P->hasAttr<PassObjectSizeAttr>();
1219 if (llvm::any_of(CallOperator->
parameters(), HasPassObjectSizeAttr))
1233 ConvExtInfo.TypeQuals.addConst();
1290 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1300 CallOpConvTL.setParam(I, From);
1301 CallOpConvNameTL.setParam(I, From);
1320 Loc, ConversionName,
1326 Class->
addDecl(ConversionTemplate);
1349 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I)
1350 InvokerParams[I]->setOwningFunction(Invoke);
1358 S.
Context, Class, Loc, InvokerName,
1364 Class->
addDecl(StaticInvokerTemplate);
1382 ConversionEPI.TypeQuals.addConst();
1408 IsImplicitCapture ? ImplicitCaptureLoc : Capture.
getLocation();
1429 Var->getIdentifier(), Field->
getType(), Loc);
1432 return Init.
Perform(S, Entity, InitKind, Ref);
1439 return BuildLambdaExpr(StartLoc, Body->
getEndLoc(), &LSI);
1453 llvm_unreachable(
"block capture in lambda");
1455 llvm_unreachable(
"Unknown implicit capture style");
1469 ? getCurrentThisType()->getPointeeType()
1477 return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
1478 !RD->hasTrivialDestructor();
1485 if (CaptureHasSideEffects(From))
1491 auto diag =
Diag(From.
getLocation(), diag::warn_unused_lambda_capture);
1512 bool ExplicitParams;
1513 bool ExplicitResultType;
1515 bool ContainsUnexpandedParameterPack;
1516 bool IsGenericLambda;
1528 Decl *TemplateOrNonTemplateCallOperatorDecl =
1531 : cast<Decl>(CallOperator);
1534 Class->
addDecl(TemplateOrNonTemplateCallOperatorDecl);
1536 PopExpressionEvaluationContext();
1541 bool CurHasPreviousCapture = CaptureDefault !=
LCD_None;
1543 CaptureDefaultLoc : IntroducerRange.
getBegin();
1545 for (
unsigned I = 0, N = LSI->
Captures.size(); I != N; ++I, ++CurField) {
1548 assert(!From.
isBlockCapture() &&
"Cannot capture __block variables");
1555 bool IsCaptureUsed =
true;
1556 if (!CurContext->isDependentContext() && !IsImplicit && !From.
isODRUsed()) {
1558 bool NonODRUsedInitCapture =
1560 if (!NonODRUsedInitCapture) {
1564 if (!CurHasPreviousCapture && !IsLast) {
1568 getLocForEndOfToken(CaptureRange.
getEnd()));
1571 FixItRange =
SourceRange(getLocForEndOfToken(PrevCaptureLoc),
1576 IsCaptureUsed = !DiagnoseUnusedLambdaCapture(FixItRange, From);
1581 CurHasPreviousCapture |= IsCaptureUsed;
1582 PrevCaptureLoc = CaptureRange.
getEnd();
1590 if (getLangOpts().CPlusPlus2a && IsImplicit &&
1593 Diag(CaptureDefaultLoc, diag::note_deprecated_this_capture)
1595 getLocForEndOfToken(CaptureDefaultLoc),
", this");
1607 CaptureInits.push_back(
nullptr);
1618 *
this, From, *CurField, CaptureDefaultLoc, IsImplicit);
1619 if (InitResult.isInvalid())
1621 Init = InitResult.get();
1623 CaptureInits.push_back(Init);
1631 if (Captures.empty() && CaptureDefault ==
LCD_None)
1641 if (getLangOpts().Blocks && getLangOpts().ObjC && !IsGenericLambda)
1648 CheckCompletedCXXClass(Class);
1651 Cleanup.mergeFrom(LambdaCleanup);
1654 CaptureDefault, CaptureDefaultLoc,
1656 ExplicitParams, ExplicitResultType,
1657 CaptureInits, EndLoc,
1658 ContainsUnexpandedParameterPack);
1664 !isa<CoroutineBodyStmt>(CallOperator->
getBody()) &&
1668 CheckConstexprFunctionDecl(CallOperator) &&
1669 CheckConstexprFunctionBody(CallOperator, CallOperator->
getBody()));
1673 DiagnoseShadowingLambdaDecls(LSI);
1675 if (!CurContext->isDependentContext()) {
1676 switch (ExprEvalContexts.back().Context) {
1680 case ExpressionEvaluationContext::Unevaluated:
1681 case ExpressionEvaluationContext::UnevaluatedList:
1682 case ExpressionEvaluationContext::UnevaluatedAbstract:
1692 case ExpressionEvaluationContext::ConstantEvaluated:
1696 ExprEvalContexts.back().Lambdas.push_back(Lambda);
1699 case ExpressionEvaluationContext::DiscardedStatement:
1700 case ExpressionEvaluationContext::PotentiallyEvaluated:
1701 case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
1706 return MaybeBindToTemporary(Lambda);
1716 = cast<CXXMethodDecl>(
1725 CurrentLocation, Src);
1727 Init = ActOnFinishFullExpr(Init.
get(),
false);
1742 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1760 ConvLocation,
nullptr,
1773 ExprCleanupObjects.push_back(Block);
1774 Cleanup.setExprNeedsCleanups(
true);
void setImplicit(bool I=true)
Represents a function declaration or definition.
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
SourceLocation getBeginLoc() const
A class which contains all the information about a particular captured value.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
bool ExplicitParams
Whether the (empty) parameter list is explicit.
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the AutoTemplateP...
bool SetTypeQual(TQ T, SourceLocation Loc)
VarDecl * createLambdaInitCaptureVarDecl(SourceLocation Loc, QualType InitCaptureType, IdentifierInfo *Id, unsigned InitStyle, Expr *Init)
Create a dummy variable within the declcontext of the lambda's call operator, for name lookup purpose...
Stmt - This represents one statement.
An instance of this object exists for each enum constant that is defined.
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
Decl - This represents one declaration (or definition), e.g.
bool isVariadic() const
Whether this function prototype is variadic.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
bool isCopyCapture() const
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The base class of the type hierarchy.
void setParams(ArrayRef< ParmVarDecl *> NewParamInfo)
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
RefQualifierKind RefQualifier
A container of type source information.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
void setInitStyle(InitializationStyle Style)
Describes the capture of a variable or of this, or of a C++1y init-capture.
This file provides some common utility functions for processing Lambda related AST Constructs...
Represents a variable declaration or definition.
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, bool isExplicit, bool isConstexpr, SourceLocation EndLocation)
bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, const sema::Capture &From)
Diagnose if an explicit lambda capture is unused.
Information about one declarator, including the parsed type information and the identifier.
QualType getReturnType() const
const T * getAs() const
Member-template getAs<specific type>'.
Extra information about a function prototype.
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
MangleNumberingContext & getMangleNumberingContext(ASTContext &Ctx)
Retrieve the mangling numbering context, used to consistently number constructs like lambdas for mang...
static InitializationKind CreateDirectList(SourceLocation InitLoc)
bool isParameterPack() const
Whether this declaration is a parameter pack.
bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt)
Try to capture the given variable.
bool CaptureHasSideEffects(const sema::Capture &From)
Does copying/destroying the captured variable have side effects?
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Represents a parameter to a function.
CXXRecordDecl * createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo *Info, bool KnownDependent, LambdaCaptureDefault CaptureDefault)
Create a new lambda closure type.
Defines the clang::Expr interface and subclasses for C++ expressions.
The collection of all-type qualifiers we support.
tok::TokenKind ContextKind
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Scope * getTemplateParamParent()
FunctionType::ExtInfo ExtInfo
One of these records is kept for each identifier that is lexed.
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ArrayRef< QualType > getParamTypes() const
field_range fields() const
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
SourceLocation getBeginLoc() const LLVM_READONLY
std::unique_ptr< MangleNumberingContext > createMangleNumberingContext() const
LambdaCaptureKind
The different capture forms in a lambda introducer.
Represents a member of a struct/union/class.
bool isReferenceType() const
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
void setParams(ArrayRef< ParmVarDecl *> NewParamInfo)
SourceLocation getBeginLoc() const LLVM_READONLY
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, bool DependentLambda, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
ArrayRef< ParmVarDecl * > parameters() const
DeclClass * getAsSingle() const
bool isThisCapture() const
Expr * getInitExpr() const
void setNameLoc(SourceLocation Loc)
Represents the results of name lookup.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
< Capturing the *this object by copy
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit=false, bool BuildAndDiagnose=true, const unsigned *const FunctionScopeIndexToStopAt=nullptr, bool ByCopy=false)
Make sure the value of 'this' is actually available in the current context, if it is a potentially ev...
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl)
Set the mangling number and context declaration for a lambda class.
CXXMethodDecl * startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, TypeSourceInfo *MethodType, SourceLocation EndLoc, ArrayRef< ParmVarDecl *> Params, bool IsConstexprSpecified)
Start the definition of a lambda expression.
void finishedExplicitCaptures()
Note when all explicit captures have been added.
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Scope - A scope is a transient data structure that is used while parsing the program.
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence...
field_iterator field_begin() const
static EnumDecl * findCommonEnumForBlockReturns(ArrayRef< ReturnStmt *> returns)
Attempt to find a common type T for which all of the returned expressions in a block are enumerator-l...
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
Represents a C++ nested-name-specifier or a global scope specifier.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
const LangOptions & getLangOpts() const
bool isLambdaCallOperator(const CXXMethodDecl *MD)
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
StringRef getLambdaStaticInvokerName()
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
QualType getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType)
Get the return type to use for a lambda's conversion function(s) to function pointer type...
static void addFunctionPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to function pointer, as described in C++11 [expr.prim.lambda]p6.
SmallVector< TemplateTypeParmDecl *, 4 > AutoTemplateParams
Store the list of the auto parameters for a generic lambda.
static ExprResult performLambdaVarCaptureInitialization(Sema &S, const Capture &Capture, FieldDecl *Field, SourceLocation ImplicitCaptureLoc, bool IsImplicitCapture)
DeclSpec & getOrCreateMethodQualifiers()
void addLambdaParameters(ArrayRef< LambdaIntroducer::LambdaCapture > Captures, CXXMethodDecl *CallOperator, Scope *CurScope)
Introduce the lambda parameters into scope.
TypeSpecTypeLoc pushTypeSpec(QualType T)
Pushes space for a typespec TypeLoc.
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
ExtInfo withCallingConv(CallingConv cc) const
ImplicitCaptureStyle ImpCaptureStyle
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
CompoundStmt - This represents a group of statements like { stmt stmt }.
bool Mutable
Whether this is a mutable lambda.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
Represents a prototype with parameter type info, e.g.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
DeclarationNameTable DeclarationNames
void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI)
Note that we have finished the explicit captures for the given lambda.
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
SmallVector< LambdaCapture, 4 > Captures
SourceLocation PotentialThisCaptureLocation
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
bool isVariableCapture() const
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, Scope *CurScope)
ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed...
This represents one expression.
bool isVariadic() const
Whether this function is variadic.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, IdentifierInfo *Id, bool DirectInit, Expr *&Init)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
const T * castAs() const
Member-template castAs<specific type>.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void setRetValue(Expr *E)
bool isFileContext() const
DeclContext * getDeclContext()
bool isConstexprSpecified() const
static TemplateParameterList * getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, Sema &SemaRef)
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, bool Mutable)
Endow the lambda scope info with the relevant properties.
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
bool isFunctionOrMethod() const
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Direct list-initialization (C++11)
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< LambdaCapture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr *> CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
static bool isInInlineFunction(const DeclContext *DC)
Determine whether the given context is or is enclosed in an inline function.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
SourceLocation getEnd() const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
struct CXXOpName CXXOperatorName
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Represents a C++ conversion function within a class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
TypeLoc getReturnLoc() const
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
SourceLocation getEndLoc() const LLVM_READONLY
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
FieldDecl * buildInitCaptureField(sema::LambdaScopeInfo *LSI, VarDecl *Var)
Build the implicit field for an init-capture.
void setIsVariadic(bool value)
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, sema::LambdaScopeInfo *LSI)
Complete a lambda-expression having processed and attached the lambda body.
void setIsConversionFromLambda(bool val=true)
SourceLocation DefaultLoc
bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)
Return true if L has a weaker nullability annotation than R.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
VarDecl * getVariable() const
ExtProtoInfo getExtProtoInfo() const
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType getReturnType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
CXXRecordDecl * Lambda
The class that describes the lambda.
static Optional< unsigned > getStackIndexOfNearestEnclosingCaptureReadyLambda(ArrayRef< const clang::sema::FunctionScopeInfo *> FunctionScopes, VarDecl *VarToCapture)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
void setReferenced(bool R=true)
Represents a static or instance method of a struct/union/class.
No ref-qualifier was provided.
C-style initialization with assignment.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isVLATypeCapture() const
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Describes the kind of initialization being performed, along with location information for tokens rela...
SmallVector< Capture, 4 > Captures
Captures - The captures.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
MangleNumberingContext * getCurrentMangleNumberContext(const DeclContext *DC, Decl *&ManglingContextDecl)
Compute the mangling number context for a lambda expression or block literal.
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
static EnumDecl * findEnumForBlockReturn(Expr *E)
If this expression is an enumerator-like expression of some type T, return the type T; otherwise...
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
This file provides some common utility functions for processing Lambdas.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Dataflow Directional Tag Classes.
void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, bool IsInstantiation=false)
ActOnLambdaError - If there is an error parsing a lambda, this callback is invoked to pop the informa...
void setBody(CompoundStmt *B)
LambdaCaptureDefault Default
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI)
Deduce a block or lambda's return type based on the return statements present in the body...
Optional< unsigned > getStackIndexOfNearestEnclosingCaptureCapableLambda(ArrayRef< const sema::FunctionScopeInfo *> FunctionScopes, VarDecl *VarToCapture, Sema &S)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const Expr * getInit() const
static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to block pointer.
The name of a declaration.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
void setInitCapture(bool IC)
Capturing variable-length array type.
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
TypeSourceInfo * getTypeSourceInfo() const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, bool isConstexpr, SourceLocation EndLocation)
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void addDecl(Decl *D)
Add the declaration D into this context.
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
Capturing the *this object by reference.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
void setSignatureAsWritten(TypeSourceInfo *Sig)
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Call-style initialization (C++98)
TranslationUnitDecl * getTranslationUnitDecl() const
Describes the sequence of initializations required to initialize a given object or reference with a s...
Represents a C++ struct/union/class.
void setConstexpr(bool IC)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Defines the clang::TargetInfo interface.
Represents a complete lambda introducer.
bool HasImplicitReturnType
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
A reference to a declared variable, function, enum, etc.
bool isNonODRUsed() const
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
bool empty() const
Return true if no decls were found.
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
A trivial tuple used to represent a source range.
void setLexicalDeclContext(DeclContext *DC)
This represents a decl that may have a name.
bool isTranslationUnit() const
void setAccess(AccessSpecifier AS)
void setBlockMissingReturnType(bool val=true)
Describes an entity that is being initialized.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Wrapper for source info for pointers.
SourceLocation getBegin() const
bool isBlockCapture() const
static void adjustBlockReturnsToEnum(Sema &S, ArrayRef< ReturnStmt *> returns, QualType returnType)
Adjust the given return statements so that they formally return the given type.
Declaration of a template function.
Attr - This represents one attribute.
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.