27 #include "llvm/ADT/STLExtras.h"
29 using namespace clang;
67 static inline std::optional<unsigned>
72 const std::optional<unsigned> NoLambdaIsCaptureReady;
75 unsigned CurScopeIndex = FunctionScopes.size() - 1;
76 while (CurScopeIndex > 0 && isa<clang::sema::CapturedRegionScopeInfo>(
77 FunctionScopes[CurScopeIndex]))
80 isa<clang::sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]) &&
81 "The function on the top of sema's function-info stack must be a lambda");
84 const bool IsCapturingThis = !VarToCapture;
85 const bool IsCapturingVariable = !IsCapturingThis;
89 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex])->CallOperator;
93 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]);
101 if (IsCapturingVariable &&
103 return NoLambdaIsCaptureReady;
122 if (IsCapturingVariable && !LSI->
isCaptured(VarToCapture))
123 return NoLambdaIsCaptureReady;
125 return NoLambdaIsCaptureReady;
129 assert(CurScopeIndex);
135 assert(CurScopeIndex < (FunctionScopes.size() - 1));
139 return CurScopeIndex + 1;
140 return NoLambdaIsCaptureReady;
178 std::optional<unsigned>
183 const std::optional<unsigned> NoLambdaIsCaptureCapable;
185 const std::optional<unsigned> OptionalStackIndex =
188 if (!OptionalStackIndex)
189 return NoLambdaIsCaptureCapable;
191 const unsigned IndexOfCaptureReadyLambda = *OptionalStackIndex;
192 assert(((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) ||
194 "The capture ready lambda for a potential capture can only be the "
195 "current lambda if it is a generic lambda");
198 cast<sema::LambdaScopeInfo>(FunctionScopes[IndexOfCaptureReadyLambda]);
201 const bool IsCapturingThis = !VarToCapture;
202 const bool IsCapturingVariable = !IsCapturingThis;
204 if (IsCapturingVariable) {
209 const bool CanCaptureVariable =
215 DeclRefType, &IndexOfCaptureReadyLambda);
216 if (!CanCaptureVariable)
217 return NoLambdaIsCaptureCapable;
222 const bool CanCaptureThis =
226 &IndexOfCaptureReadyLambda);
228 return NoLambdaIsCaptureCapable;
230 return IndexOfCaptureReadyLambda;
249 unsigned LambdaDependencyKind,
255 bool IsGenericLambda =
259 Context, DC, Info, IntroducerRange.
getBegin(), LambdaDependencyKind,
260 IsGenericLambda, CaptureDefault);
270 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
280 std::tuple<MangleNumberingContext *, Decl *>
284 Decl *ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
295 bool IsInNonspecializedTemplate =
296 inTemplateInstantiation() || CurContext->isDependentContext();
301 if (ManglingContextDecl) {
302 if (
ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
305 if (LexicalDC->isRecord())
306 Kind = DefaultArgument;
307 }
else if (
VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
308 if (Var->getMostRecentDecl()->isInline())
309 Kind = InlineVariable;
310 else if (Var->getDeclContext()->isRecord() && IsInNonspecializedTemplate)
311 Kind = TemplatedVariable;
312 else if (Var->getDescribedVarTemplate())
313 Kind = TemplatedVariable;
314 else if (
auto *VTS = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
315 if (!VTS->isExplicitSpecialization())
316 Kind = TemplatedVariable;
318 }
else if (isa<FieldDecl>(ManglingContextDecl)) {
320 }
else if (isa<ImplicitConceptSpecializationDecl>(ManglingContextDecl)) {
331 if ((IsInNonspecializedTemplate &&
332 !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
334 while (
auto *CD = dyn_cast<CapturedDecl>(DC))
339 return std::make_tuple(
nullptr,
nullptr);
349 case DefaultArgument:
352 case TemplatedVariable:
354 return std::make_tuple(
356 ManglingContextDecl),
357 ManglingContextDecl);
360 llvm_unreachable(
"unexpected context");
367 assert(MethodTypeInfo &&
"expected a non null type");
373 if (
Class->isDependentContext() || TemplateParams) {
376 if (Result->isUndeducedType()) {
407 QualType LambdaType = getASTContext().getRecordType(RD);
408 if (LambdaType == ExplicitObjectParameterType)
427 return It->second.empty();
432 if (!IsDerivedFrom(RD->
getLocation(), ExplicitObjectParameterType, LambdaType,
434 Diag(Param->
getLocation(), diag::err_invalid_explicit_object_type_in_lambda)
435 << ExplicitObjectParameterType;
440 std::string PathsDisplay = getAmbiguousPathsDisplayString(Paths);
441 Diag(CallLoc, diag::err_explicit_object_lambda_ambiguous_base)
442 << LambdaType << PathsDisplay;
446 if (CheckBaseClassAccess(CallLoc, LambdaType, ExplicitObjectParameterType,
448 diag::err_explicit_object_lambda_inaccessible_base))
457 std::optional<CXXRecordDecl::LambdaNumbering> NumberingOverride) {
458 if (NumberingOverride) {
459 Class->setLambdaNumbering(*NumberingOverride);
465 auto getMangleNumberingContext =
469 if (ManglingContextDecl)
473 auto DC =
Class->getDeclContext();
474 while (
auto *CD = dyn_cast<CapturedDecl>(DC))
475 DC = CD->getParent();
482 getCurrentMangleNumberContext(
Class->getDeclContext());
483 if (!MCtx && (getLangOpts().
CUDA || getLangOpts().SYCLIsDevice ||
484 getLangOpts().SYCLIsHost)) {
493 assert(MCtx &&
"Retrieving mangle numbering context failed!");
500 Class->setLambdaNumbering(Numbering);
504 Source->AssignedLambdaNumbering(
Class);
510 bool ExplicitResultType) {
511 if (ExplicitResultType) {
516 diag::err_lambda_incomplete_result);
526 bool ExplicitParams,
bool Mutable) {
529 LSI->
Lambda = LambdaClass;
549 assert(LSI &&
"Expected a lambda scope");
551 "Already acted on explicit template parameters");
553 "Explicit template parameters should come "
554 "before invented (auto) ones");
555 assert(!TParams.empty() &&
556 "No template parameters to act on");
578 = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
579 return cast<EnumDecl>(D->getDeclContext());
587 if (BO->getOpcode() == BO_Comma)
594 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
595 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
616 if (ICE->getCastKind() == CK_IntegralCast)
624 return ET->getDecl();
647 if (!ED)
return nullptr;
650 for (++i; i != e; ++i) {
666 i = returns.begin(), e = returns.end(); i != e; ++i) {
694 assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().
CPlusPlus14) &&
695 "lambda expressions use auto deduction in C++14 onwards");
732 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
738 assert(isa<BlockScopeInfo>(CSI));
761 (RetE ? RetE->
getType() : Context.
VoidTy).getUnqualifiedType();
767 if (BlockNullability &&
768 (!RetTyNullability ||
777 diag::err_typecheck_missing_return_type_incompatible)
778 << ReturnType << CSI.
ReturnType << isa<LambdaScopeInfo>(CSI);
786 bool IsDirectInit,
Expr *&Init) {
794 DeductType = BuildReferenceType(DeductType,
true,
Loc,
Id);
795 assert(!DeductType.
isNull() &&
"can't build reference to auto");
799 if (Init->containsUnexpandedParameterPack()) {
801 ? diag::warn_cxx17_compat_init_capture_pack
802 : diag::ext_init_capture_pack);
821 ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
830 Loc, Init->getBeginLoc(), Init->getEndLoc())
842 if (Result.isInvalid())
845 Init = Result.getAs<
Expr>();
856 PETL.setEllipsisLoc(EllipsisLoc);
863 InitCaptureType, TSI,
SC_Auto);
871 getCurLambda()->LocalPacks.push_back(NewVD);
876 assert(Var->
isInitCapture() &&
"init capture flag should be set");
919 bool &ExplicitResultType) {
921 ExplicitResultType =
false;
927 "Unexpected storage specifier");
928 bool IsLambdaStatic =
941 bool HasExplicitObjectParameter =
946 !HasExplicitObjectParameter)
957 diag::err_return_value_with_address_space);
962 assert(MethodTyInfo &&
"no type from lambda-declarator");
990 getCurFPFeatures().isFPConstrained(),
1000 assert(TemplateParams &&
"no template parameters");
1003 TemplateParams, CallOperator);
1013 bool HasExplicitResultType) {
1017 if (TrailingRequiresClause)
1025 if (TemplateParams) {
1028 assert(TemplateMethod &&
1029 "AddTemplateParametersToLambdaCallOperator should have been called");
1044 TemplateParams, MethodTyInfo));
1047 if (!Params.empty()) {
1048 CheckParmsForFunctionDef(Params,
false);
1051 assert(
P &&
"null in a parameter list");
1052 P->setOwningFunction(Method);
1060 Scope *CurrentScope) {
1063 assert(LSI &&
"LambdaScopeInfo should be on stack!");
1081 assert(TemplateParamScope &&
1082 "Lambda with explicit template param list should establish a "
1083 "template param scope");
1084 assert(TemplateParamScope->
getParent());
1087 }
else if (CurScope->getTemplateParamParent() !=
nullptr) {
1092 Intro.
Range,
nullptr, LambdaDependencyKind, Intro.
Default);
1099 PushDeclContext(CurScope, Method);
1101 bool ContainsUnexpandedParameterPack =
false;
1104 llvm::DenseMap<IdentifierInfo *, ValueDecl *> CaptureNames;
1110 PrevCaptureLoc = C->Loc, ++C) {
1114 ? diag::ext_star_this_lambda_capture_cxx17
1115 : diag::warn_cxx14_compat_star_this_lambda_capture);
1121 Diag(C->Loc, diag::err_capture_more_than_once)
1124 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1135 ? diag::ext_equals_this_lambda_capture_cxx20
1136 : diag::warn_cxx17_compat_equals_this_lambda_capture);
1141 QualType ThisCaptureType = getCurrentThisType();
1142 if (ThisCaptureType.
isNull()) {
1143 Diag(C->Loc, diag::err_this_capture) <<
true;
1147 CheckCXXThisCapture(C->Loc,
true,
true,
1155 assert(C->Id &&
"missing identifier for capture");
1157 if (C->Init.isInvalid())
1161 if (C->Init.isUsable()) {
1163 ? diag::warn_cxx11_compat_init_capture
1164 : diag::ext_init_capture);
1171 if (C->InitCaptureType.get().isNull())
1174 if (C->Init.get()->containsUnexpandedParameterPack() &&
1176 DiagnoseUnexpandedParameterPack(C->Init.get(), UPPC_Initializer);
1179 switch (C->InitKind) {
1181 llvm_unreachable(
"not an init-capture?");
1192 Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1193 C->EllipsisLoc, C->Id, InitStyle,
1194 C->Init.get(), Method);
1195 assert(Var &&
"createLambdaInitCaptureVarDecl returned a null VarDecl?");
1196 if (
auto *
V = dyn_cast<VarDecl>(Var))
1197 CheckShadow(CurrentScope,
V);
1198 PushOnScopeChains(Var, CurrentScope,
false);
1201 "init capture has valid but null init?");
1209 Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1211 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1214 Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1216 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1225 LookupName(R, CurScope);
1232 if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R, Validator))
1240 if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1249 Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1256 if (
auto [It, Inserted] = CaptureNames.insert(std::pair{C->Id, Var});
1260 Diag(C->Loc, diag::err_capture_more_than_once)
1261 << C->Id << It->second->getBeginLoc()
1263 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1266 DiagPlaceholderVariableDefinition(C->Loc);
1270 Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1282 Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1290 if (C->EllipsisLoc.isValid()) {
1292 EllipsisLoc = C->EllipsisLoc;
1294 Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1295 << (C->Init.isUsable() ? C->Init.get()->getSourceRange()
1301 ContainsUnexpandedParameterPack =
true;
1304 if (C->Init.isUsable()) {
1305 addInitCapture(LSI, cast<VarDecl>(Var), C->Kind ==
LCK_ByRef);
1306 PushOnScopeChains(Var, CurScope,
false);
1309 : TryCapture_ExplicitByVal;
1310 tryCaptureVariable(Var, C->Loc,
Kind, EllipsisLoc);
1315 finishLambdaExplicitCaptures(LSI);
1340 (getCurrentThisType().isNull() ||
1352 auto *Param = cast<ParmVarDecl>(
P.Param);
1354 if (Param->getIdentifier())
1355 PushOnScopeChains(Param, LambdaScope,
false);
1364 if (TemplateParams) {
1380 bool ExplicitResultType;
1398 *
this, Intro, ParamInfo, getCurScope(),
TypeLoc, ExplicitResultType);
1405 Params.reserve(Params.size());
1406 for (
unsigned I = 0; I < FTI.NumParams; ++I) {
1407 auto *Param = cast<ParmVarDecl>(FTI.Params[I].Param);
1408 Param->setScopeInfo(0, Params.size());
1409 Params.push_back(Param);
1413 bool IsLambdaStatic =
1416 CompleteLambdaCallOperator(
1422 CheckCXXDefaultArguments(Method);
1426 AddRangeBasedOptnone(Method);
1429 if (
Attr *A = getImplicitCodeSegOrSectionAttrForFunction(
1434 ProcessDeclAttributes(CurScope, Method, ParamInfo);
1437 if (getLangOpts().
CUDA)
1438 CUDA().SetLambdaAttrs(Method);
1441 if (LangOpts.OpenMP)
1442 OpenMP().ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Method);
1444 handleLambdaNumbering(
Class, Method);
1447 if (!C.isVariableCapture())
1451 PushOnScopeChains(Var, CurScope,
false);
1455 auto CheckRedefinition = [&](
ParmVarDecl *Param) {
1457 if (
Capture.Id == Param->getIdentifier()) {
1458 Diag(Param->getLocation(), diag::err_parameter_shadow_capture);
1459 Diag(
Capture.Loc, diag::note_var_explicitly_captured_here)
1468 if (!
P->getIdentifier())
1470 if (CheckRedefinition(
P))
1471 CheckShadow(CurScope,
P);
1472 PushOnScopeChains(
P, CurScope);
1482 if (TemplateParams) {
1483 for (
const auto *TP : TemplateParams->
asArray()) {
1484 if (!TP->getIdentifier())
1487 if (
Capture.Id == TP->getIdentifier()) {
1489 NoteTemplateParameterLocation(*TP);
1522 Diag(TRC->getBeginLoc(), diag::err_constrained_non_templated_function);
1528 PushExpressionEvaluationContext(
1530 ? ExpressionEvaluationContext::ImmediateFunctionContext
1531 : ExpressionEvaluationContext::PotentiallyEvaluated);
1532 ExprEvalContexts.back().InImmediateFunctionContext =
1534 ExprEvalContexts.back().InImmediateEscalatingFunctionContext =
1539 bool IsInstantiation) {
1543 DiscardCleanupsInEvaluationContext();
1544 PopExpressionEvaluationContext();
1547 if (!IsInstantiation)
1552 Class->setInvalidDecl();
1556 CheckCompletedCXXClass(
nullptr,
Class);
1558 PopFunctionScopeInfo();
1561 template <
typename Func>
1585 DefaultFree, DefaultMember, CallOpCC};
1587 llvm::iterator_range<CallingConv *>
Range(
1588 std::begin(Convs), std::unique(std::begin(Convs), std::end(Convs)));
1598 if (CallOpCC == DefaultMember && DefaultMember != DefaultFree) {
1620 if (CallOpCC == DefaultMember && DefaultMember != DefaultFree)
1633 "Lambda's call operator should not have a reference qualifier");
1646 auto HasPassObjectSizeAttr = [](
const ParmVarDecl *
P) {
1647 return P->hasAttr<PassObjectSizeAttr>();
1649 if (llvm::any_of(CallOperator->
parameters(), HasPassObjectSizeAttr))
1719 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1729 CallOpConvTL.setParam(I, From);
1730 CallOpConvNameTL.setParam(I, From);
1749 if (
Class->isGenericLambda()) {
1756 Loc, ConversionName,
1762 Class->addDecl(ConversionTemplate);
1764 Class->addDecl(Conversion);
1790 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I)
1791 InvokerParams[I]->setOwningFunction(Invoke);
1795 if (
Class->isGenericLambda()) {
1805 Class->addDecl(StaticInvokerTemplate);
1807 Class->addDecl(Invoke);
1863 Class->addDecl(Conversion);
1868 bool IsOpenMPMapping) {
1875 return cast<VarDecl>(Cap.
getVariable())->getInit();
1898 QualType ThisTy = getCurrentThisType();
1901 Init = CreateBuiltinUnaryOp(
Loc, UO_Deref,
This);
1908 Init = BuildDeclarationNameExpr(
1915 if (IsOpenMPMapping)
1918 if (Init.isInvalid())
1921 Expr *InitExpr = Init.get();
1927 return InitSeq.
Perform(*
this, Entity, InitKind, InitExpr);
1933 return BuildLambdaExpr(StartLoc, Body->
getEndLoc(), &LSI);
1947 llvm_unreachable(
"block capture in lambda");
1949 llvm_unreachable(
"Unknown implicit capture style");
1955 if (Init && Init->HasSideEffects(Context))
1963 ? getCurrentThisType()->getPointeeType()
1966 if (
T.isVolatileQualified())
1971 return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
1972 !RD->hasTrivialDestructor();
1979 if (CaptureHasSideEffects(From))
1991 auto diag =
Diag(From.
getLocation(), diag::warn_unused_lambda_capture);
2012 const auto *Var = dyn_cast_or_null<VarDecl>(Val);
2014 if (Var && Var->isInitCapture())
2015 TSI = Var->getTypeSourceInfo();
2021 if (getLangOpts().SYCLIsDevice || getLangOpts().SYCLIsHost) {
2022 StringRef CaptureName = Val ? Val->
getName() :
"";
2023 if (!CaptureName.empty())
2036 FieldType, TSI,
nullptr,
2041 if (RequireCompleteSizedType(
Loc, FieldType,
2042 diag::err_field_incomplete_or_sizeless)) {
2044 Field->setInvalidDecl();
2050 Field->setInvalidDecl();
2054 Field->setImplicit(
true);
2075 bool ExplicitParams;
2076 bool ExplicitResultType;
2078 bool ContainsUnexpandedParameterPack;
2079 bool IsGenericLambda;
2088 IsGenericLambda =
Class->isGenericLambda();
2091 Decl *TemplateOrNonTemplateCallOperatorDecl =
2094 : cast<Decl>(CallOperator);
2100 PopExpressionEvaluationContext();
2103 bool CurHasPreviousCapture = CaptureDefault !=
LCD_None;
2105 CaptureDefaultLoc : IntroducerRange.
getBegin();
2107 for (
unsigned I = 0, N = LSI->
Captures.size(); I != N; ++I) {
2113 assert(!From.
isBlockCapture() &&
"Cannot capture __block variables");
2122 bool IsCaptureUsed =
true;
2123 if (!CurContext->isDependentContext() && !IsImplicit &&
2127 bool NonODRUsedInitCapture =
2129 if (!NonODRUsedInitCapture) {
2133 if (!CurHasPreviousCapture && !IsLast) {
2137 getLocForEndOfToken(CaptureRange.
getEnd()));
2140 FixItRange =
SourceRange(getLocForEndOfToken(PrevCaptureLoc),
2145 IsCaptureUsed = !DiagnoseUnusedLambdaCapture(FixItRange, From);
2150 CurHasPreviousCapture |= IsCaptureUsed;
2151 PrevCaptureLoc = CaptureRange.
getEnd();
2163 Diag(CaptureDefaultLoc, diag::note_deprecated_this_capture)
2165 getLocForEndOfToken(CaptureDefaultLoc),
", this");
2182 ExprResult Init = BuildCaptureInit(From, ImplicitCaptureLoc);
2189 BuildCaptureField(
Class, From);
2191 CaptureInits.push_back(Init.get());
2194 CUDA().CheckLambdaCapture(CallOperator, From);
2197 Class->setCaptures(Context, Captures);
2204 if (Captures.empty() && CaptureDefault ==
LCD_None)
2214 if (getLangOpts().Blocks && getLangOpts().ObjC && !IsGenericLambda)
2221 CheckCompletedCXXClass(
nullptr,
Class);
2224 Cleanup.mergeFrom(LambdaCleanup);
2227 CaptureDefault, CaptureDefaultLoc,
2228 ExplicitParams, ExplicitResultType,
2229 CaptureInits, EndLoc,
2230 ContainsUnexpandedParameterPack);
2236 !isa<CoroutineBodyStmt>(CallOperator->
getBody()) &&
2237 !
Class->getDeclContext()->isDependentContext()) {
2239 CheckConstexprFunctionDefinition(CallOperator,
2240 CheckConstexprKind::CheckValid)
2246 DiagnoseShadowingLambdaDecls(LSI);
2248 if (!CurContext->isDependentContext()) {
2249 switch (ExprEvalContexts.back().Context) {
2253 case ExpressionEvaluationContext::Unevaluated:
2254 case ExpressionEvaluationContext::UnevaluatedList:
2255 case ExpressionEvaluationContext::UnevaluatedAbstract:
2265 case ExpressionEvaluationContext::ConstantEvaluated:
2266 case ExpressionEvaluationContext::ImmediateFunctionContext:
2270 ExprEvalContexts.back().Lambdas.push_back(Lambda);
2273 case ExpressionEvaluationContext::DiscardedStatement:
2274 case ExpressionEvaluationContext::PotentiallyEvaluated:
2275 case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
2280 return MaybeBindToTemporary(Lambda);
2290 = cast<CXXMethodDecl>(
2298 CurrentLocation, Src);
2299 if (!Init.isInvalid())
2300 Init = ActOnFinishFullExpr(Init.get(),
false);
2302 if (Init.isInvalid())
2311 Block->setBlockMissingReturnType(
false);
2315 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
2323 Block->setParams(BlockParams);
2325 Block->setIsConversionFromLambda(
true);
2333 ConvLocation,
nullptr,
2346 ExprCleanupObjects.push_back(
Block);
2347 Cleanup.setExprNeedsCleanups(
true);
2386 SemaRef.addInstantiatedCapturesToScope(FD, Pattern,
Scope, MLTAL);
2389 while (ShouldAddDeclsFromParentScope) {
2396 if (!FD || !Pattern)
2399 SemaRef.addInstantiatedParametersToScope(ParentFD, Pattern,
Scope, MLTAL);
2400 SemaRef.addInstantiatedLocalVarsToScope(ParentFD, Pattern,
Scope);
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines the clang::Expr interface and subclasses for C++ expressions.
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.
This file declares semantic analysis for CUDA constructs.
static void BuildBasePathArray(const CXXBasePath &Path, CXXCastPath &BasePathArray)
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
static CallingConv getLambdaConversionFunctionCallConv(Sema &S, const FunctionProtoType *CallOpProto)
static TemplateParameterList * getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, Sema &SemaRef)
static void adjustBlockReturnsToEnum(Sema &S, ArrayRef< ReturnStmt * > returns, QualType returnType)
Adjust the given return statements so that they formally return the given type.
static LambdaScopeInfo * getCurrentLambdaScopeUnsafe(Sema &S)
static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to block pointer.
static void buildLambdaScopeReturnType(Sema &S, LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, bool ExplicitResultType)
static FunctionDecl * getPatternFunctionDecl(FunctionDecl *FD)
static EnumDecl * findEnumForBlockReturn(Expr *E)
If this expression is an enumerator-like expression of some type T, return the type T; otherwise,...
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...
static QualType buildTypeForLambdaCallOperator(Sema &S, clang::CXXRecordDecl *Class, TemplateParameterList *TemplateParams, TypeSourceInfo *MethodTypeInfo)
static std::optional< unsigned > getStackIndexOfNearestEnclosingCaptureReadyLambda(ArrayRef< const clang::sema::FunctionScopeInfo * > FunctionScopes, ValueDecl *VarToCapture)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
static bool isInInlineFunction(const DeclContext *DC)
Determine whether the given context is or is enclosed in an inline function.
static TypeSourceInfo * getLambdaType(Sema &S, LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope, SourceLocation Loc, bool &ExplicitResultType)
static void addFunctionPointerConversions(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to function pointers, as described in C++11 [expr.prim.lambda]p6.
static void repeatForLambdaConversionFunctionCallingConvs(Sema &S, const FunctionProtoType &CallOpProto, Func F)
static void addFunctionPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator, QualType InvokerFunctionTy)
Add a lambda's conversion to function pointer, as described in C++11 [expr.prim.lambda]p6.
static TypeSourceInfo * getDummyLambdaType(Sema &S, SourceLocation Loc=SourceLocation())
This file provides some common utility functions for processing Lambdas.
This file declares semantic analysis for OpenMP constructs and clauses.
tok::TokenKind ContextKind
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
DeclarationNameTable DeclarationNames
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod, bool IsBuiltin=false) const
Retrieves the default calling convention for the current target.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
llvm::DenseMap< const CXXMethodDecl *, CXXCastPath > LambdaCastPaths
For capturing lambdas with an explicit object parameter whose type is derived from the lambda type,...
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
const TargetInfo & getTargetInfo() const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
TranslationUnitDecl * getTranslationUnitDecl() const
Attr - This represents one attribute.
A builtin binary operation expression such as "x + y" or "x <= y".
A binding in a decomposition declaration.
A class which contains all the information about a particular captured value.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a C++ conversion function within a class.
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Represents a static or instance method of a struct/union/class.
bool isImplicitObjectMemberFunction() const
[C++2b][dcl.fct]/p7 An implicit object member function is a non-static member function without an exp...
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Represents a C++ struct/union/class.
void setLambdaTypeInfo(TypeSourceInfo *TS)
void setLambdaIsGeneric(bool IsGeneric)
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
bool isCapturelessLambda() const
Represents a C++ nested-name-specifier or a global scope specifier.
CompoundStmt - This represents a group of statements like { stmt stmt }.
ConditionalOperator - The ?: ternary operator.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isFileContext() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isTranslationUnit() const
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
void addDecl(Decl *D)
Add the declaration D into this context.
bool isFunctionOrMethod() const
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
A reference to a declared variable, function, enum, etc.
Captures information about "declaration specifiers".
SCS getStorageClassSpec() const
bool SetTypeQual(TQ T, SourceLocation Loc)
ConstexprSpecKind getConstexprSpecifier() const
Decl - This represents one declaration (or definition), e.g.
bool isParameterPack() const
Whether this declaration is a parameter pack.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
bool isInvalidDecl() const
void setAccess(AccessSpecifier AS)
SourceLocation getLocation() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setImplicit(bool I=true)
void setReferenced(bool R=true)
void setLocation(SourceLocation L)
void setLexicalDeclContext(DeclContext *DC)
DeclContext * getDeclContext()
DeclarationNameLoc - Additional source/type location info for a declaration name.
static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo)
Construct location information for a constructor, destructor or conversion operator.
static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc, SourceLocation EndLoc)
Construct location information for a non-literal C++ operator.
The name of a declaration.
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
void setInnerLocStart(SourceLocation L)
SourceLocation getBeginLoc() const LLVM_READONLY
void setTypeSourceInfo(TypeSourceInfo *TI)
TypeSourceInfo * getTypeSourceInfo() const
void setTrailingRequiresClause(Expr *TrailingRequiresClause)
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
bool isExplicitObjectMemberFunction()
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
An instance of this object exists for each enum constant that is defined.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Store information needed for an explicit specifier.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Represents difference between two FPOptions values.
bool isFPConstrained() const
Represents a member of a struct/union/class.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
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 setSubExpr(Expr *E)
As with any mutator of the AST, be very careful when modifying an existing AST to preserve its invari...
const Expr * getSubExpr() const
Represents a function declaration or definition.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
ConstexprSpecKind getConstexprKind() const
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
QualType getReturnType() const
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
bool isVariadic() const
Whether this function is variadic.
@ TK_MemberSpecialization
@ TK_DependentNonTemplate
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isImmediateEscalating() const
ArrayRef< ParmVarDecl * > parameters() const
FunctionDecl * getInstantiatedFromDecl() const
void setConstexprKind(ConstexprSpecKind CSK)
void setStorageClass(StorageClass SClass)
Sets the storage class as written in the source.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
const ParmVarDecl * getParamDecl(unsigned i) const
Represents a prototype with parameter type info, e.g.
ArrayRef< QualType > getParamTypes() const
bool isVariadic() const
Whether this function prototype is variadic.
ExtProtoInfo getExtProtoInfo() const
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
TypeLoc getReturnLoc() const
ExtInfo withCallingConv(CallingConv cc) const
CallingConv getCallConv() const
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
Describes the sequence of initializations required to initialize a given object or reference with a s...
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.
Describes an entity that is being initialized.
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type)
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
Describes the capture of a variable or of this, or of a C++1y init-capture.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Represents the results of name lookup.
DeclClass * getAsSingle() const
bool empty() const
Return true if no decls were found.
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0
Retrieve the mangling number of a new lambda expression with the given call operator within this cont...
unsigned getNextLambdaIndex()
virtual unsigned getDeviceManglingNumber(const CXXMethodDecl *)
Retrieve the mangling number of a new lambda expression with the given call operator within the devic...
Data structure that captures multiple levels of template argument lists for use in template instantia...
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
bool isPlaceholderVar(const LangOptions &LangOpts) const
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents a pack expansion of types.
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Represents a parameter to a function.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Wrapper for source info for pointers.
A (possibly-)qualified type.
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
LangAS getAddressSpace() const
Return the address space of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
The collection of all-type qualifiers we support.
void addAddressSpace(LangAS space, bool AllowDefaultAddrSpace=false)
Represents a struct/union/class.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
void setRetValue(Expr *E)
SourceLocation getBeginLoc() const
Scope - A scope is a transient data structure that is used while parsing the program.
Scope * getTemplateParamParent()
const Scope * getParent() const
getParent - Return the scope that this is nested in.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
LambdaScopeForCallOperatorInstantiationRAII(Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope, bool ShouldAddDeclsFromParentScope=true)
Sema - This implements semantic analysis and AST building for C.
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
VarDecl * createLambdaInitCaptureVarDecl(SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx)
Create a dummy variable within the declcontext of the lambda's call operator, for name lookup purpose...
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body)
ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed.
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, sema::LambdaScopeInfo *LSI)
Complete a lambda-expression having processed and attached the lambda body.
CXXRecordDecl * createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo *Info, unsigned LambdaDependencyKind, LambdaCaptureDefault CaptureDefault)
Create a new lambda closure type.
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
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...
void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, Scope *CurContext)
Once the Lambdas capture are known, we can start to create the closure, call operator method,...
void AddTemplateParametersToLambdaCallOperator(CXXMethodDecl *CallOperator, CXXRecordDecl *Class, TemplateParameterList *TemplateParams)
void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef)
Add an init-capture to a lambda scope.
FieldDecl * BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture)
Build a FieldDecl suitable to hold the given capture.
sema::LambdaScopeInfo * RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator)
bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, TryCaptureKind Kind, SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt)
Try to capture the given variable.
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, std::optional< CXXRecordDecl::LambdaNumbering > NumberingOverride=std::nullopt)
Number lambda for linkage purposes if necessary.
LangAS getDefaultCXXMethodAddrSpace() const
Returns default addr space for method qualifiers.
ExprResult BuildCaptureInit(const sema::Capture &Capture, SourceLocation ImplicitCaptureLoc, bool IsOpenMPMapping=false)
Initialize the given capture with a suitable expression.
@ UPPC_DeclarationType
The type of an arbitrary declaration.
void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool Mutable)
Endow the lambda scope info with the relevant properties.
bool CaptureHasSideEffects(const sema::Capture &From)
Does copying/destroying the captured variable have side effects?
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, const DeclSpec &DS)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
void ActOnLambdaClosureParameters(Scope *LambdaScope, MutableArrayRef< DeclaratorChunk::ParamInfo > ParamInfo)
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
const LangOptions & getLangOpts() const
bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, const sema::Capture &From)
Diagnose if an explicit lambda capture is unused.
QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions, IdentifierInfo *Id, bool DirectInit, Expr *&Init)
void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > TParams, SourceLocation RAngleLoc, ExprResult RequiresClause)
This is called after parsing the explicit template parameter list on a lambda (if it exists) in C++2a...
void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, SourceLocation MutableLoc)
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...
ASTContext & getASTContext() const
TypeSourceInfo * GetTypeForDeclarator(Declarator &D)
GetTypeForDeclarator - Convert the type for the specified declarator to Type instances.
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
void CheckExplicitObjectLambda(Declarator &D)
QualType getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, CallingConv CC)
Get the return type to use for a lambda's conversion function(s) to function pointer type,...
FPOptions & getCurFPFeatures()
CXXMethodDecl * CreateLambdaCallOperator(SourceRange IntroducerRange, CXXRecordDecl *Class)
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI)
Deduce a block or lambda's return type based on the return statements present in the body.
QualType SubstAutoTypeDependent(QualType TypeWithAuto)
std::tuple< MangleNumberingContext *, Decl * > getCurrentMangleNumberContext(const DeclContext *DC)
Compute the mangling number context for a lambda expression or block literal.
void CompleteLambdaCallOperator(CXXMethodDecl *Method, SourceLocation LambdaLoc, SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause, TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind, StorageClass SC, ArrayRef< ParmVarDecl * > Params, bool HasExplicitResultType)
void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI)
Note that we have finished the explicit captures for the given lambda.
bool DiagnoseInvalidExplicitObjectParameterInLambda(CXXMethodDecl *Method, SourceLocation CallLoc)
Returns true if the explicit object parameter was invalid.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Exposes information about the current target.
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Stores a list of template parameters for a TemplateDecl and its derived classes.
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
ArrayRef< NamedDecl * > asArray()
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
void setNameLoc(SourceLocation Loc)
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
CanQualType getCanonicalTypeUnqualified() const
const T * castAs() const
Member-template castAs<specific type>.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
const T * getAs() const
Member-template getAs<specific type>'.
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
void setType(QualType newType)
VarDecl * getPotentiallyDecomposedVarDecl()
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
void setInitStyle(InitializationStyle Style)
void setInitCapture(bool IC)
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
InitializationStyle
Initialization styles.
@ ListInit
Direct list-initialization (C++11)
@ CInit
C-style initialization with assignment.
@ CallInit
Call-style initialization (C++98)
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
bool isVariableCapture() const
bool isBlockCapture() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
bool isNonODRUsed() const
bool isInitCapture() const
Determine whether this capture is an init-capture.
bool isVLATypeCapture() const
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
bool isThisCapture() const
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
bool isCopyCapture() const
ValueDecl * getVariable() const
const VariableArrayType * getCapturedVLAType() const
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
bool isCaptured(ValueDecl *Var) const
Determine whether the given variable has been captured.
SmallVector< Capture, 4 > Captures
Captures - The captures.
ImplicitCaptureStyle ImpCaptureStyle
bool HasImplicitReturnType
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
void addCapture(ValueDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
SourceLocation PotentialThisCaptureLocation
void finishedExplicitCaptures()
Note when all explicit captures have been added.
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
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 TemplateParam...
ExprResult RequiresClause
The requires-clause immediately following the explicit template parameter list, if any.
SourceRange ExplicitTemplateParamsRange
Source range covering the explicit template parameter list (if it exists).
CXXRecordDecl * Lambda
The class that describes the lambda.
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
bool AfterParameterList
Indicate that we parsed the parameter list at which point the mutability of the lambda is known.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
bool Mutable
Whether this is a mutable lambda.
Defines the clang::TargetInfo interface.
bool This(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
std::optional< unsigned > getStackIndexOfNearestEnclosingCaptureCapableLambda(ArrayRef< const sema::FunctionScopeInfo * > FunctionScopes, ValueDecl *VarToCapture, Sema &S)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
ConstexprSpecKind
Define the kind of constexpr specifier.
@ ICIS_NoInit
No in-class initializer.
@ RQ_None
No ref-qualifier was provided.
LambdaCaptureKind
The different capture forms in a lambda introducer.
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
@ LCK_ByRef
Capturing by reference.
@ LCK_VLAType
Capturing variable-length array type.
@ LCK_StarThis
Capturing the *this object by copy.
@ LCK_This
Capturing the *this object by reference.
bool isLambdaCallWithExplicitObjectParameter(const DeclContext *DC)
StorageClass
Storage classes.
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
bool FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI)
@ CopyInit
[a = b], [a = {b}]
bool isLambdaCallOperator(const CXXMethodDecl *MD)
bool hasWeakerNullability(NullabilityKind L, NullabilityKind R)
Return true if L has a weaker nullability annotation than R.
ActionResult< Expr * > ExprResult
LangAS
Defines the address space values used by the address space qualifier of QualType.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
StringRef getLambdaStaticInvokerName()
const FunctionProtoType * T
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ EST_BasicNoexcept
noexcept
MutableArrayRef< Expr * > MultiExprArg
Information about how a lambda is numbered within its context.
unsigned DeviceManglingNumber
bool HasKnownInternalLinkage
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getTrailingReturnTypeLoc() const
Get the trailing-return-type location for this function declarator.
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
DeclSpec & getOrCreateMethodQualifiers()
bool hasMutableQualifier() const
Determine whether this lambda-declarator contains a 'mutable' qualifier.
ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed.
ExceptionSpecificationType Type
The kind of exception specification this is.
Extra information about a function prototype.
ExceptionSpecInfo ExceptionSpec
RefQualifierKind RefQualifier
unsigned HasTrailingReturn
FunctionType::ExtInfo ExtInfo
unsigned NumExplicitTemplateParams
The number of parameters in the template parameter list that were explicitly specified by the user,...
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda or an abbreviated function template.
Represents a complete lambda introducer.
SmallVector< LambdaCapture, 4 > Captures
SourceLocation DefaultLoc
LambdaCaptureDefault Default
An RAII helper that pops function a function scope on exit.