37#include "llvm/Support/TimeProfiler.h"
48 return cast<CXXRecordDecl>(DC)->isLocalClass();
53template<
typename DeclT>
56 if (!OldDecl->getQualifierLoc())
59 assert((NewDecl->getFriendObjectKind() ||
60 !OldDecl->getLexicalDeclContext()->isDependentContext()) &&
61 "non-friend with qualified name defined in dependent context");
64 const_cast<DeclContext *
>(NewDecl->getFriendObjectKind()
65 ? NewDecl->getLexicalDeclContext()
66 : OldDecl->getLexicalDeclContext()));
75 NewDecl->setQualifierInfo(NewQualifierLoc);
81 return ::SubstQualifier(SemaRef, OldDecl, NewDecl, TemplateArgs);
86 return ::SubstQualifier(SemaRef, OldDecl, NewDecl, TemplateArgs);
90#include "clang/Sema/AttrTemplateInstantiate.inc"
94 const AlignedAttr *Aligned,
Decl *New,
bool IsPackExpansion) {
95 if (Aligned->isAlignmentExpr()) {
104 S.
SubstType(Aligned->getAlignmentType(), TemplateArgs,
107 Aligned->getLocation(),
108 Result->getTypeLoc().getSourceRange()))
116 const AlignedAttr *Aligned,
Decl *New) {
117 if (!Aligned->isPackExpansion()) {
123 if (Aligned->isAlignmentExpr())
129 assert(!Unexpanded.empty() &&
"Pack expansion without parameter packs?");
132 bool Expand =
true, RetainExpansion =
false;
133 std::optional<unsigned> NumExpansions;
137 Unexpanded, TemplateArgs, Expand,
138 RetainExpansion, NumExpansions))
145 for (
unsigned I = 0; I != *NumExpansions; ++I) {
154 const AssumeAlignedAttr *Aligned,
Decl *New) {
159 Expr *
E, *OE =
nullptr;
165 if (Aligned->getOffset()) {
177 const AlignValueAttr *Aligned,
Decl *New) {
188 const AllocAlignAttr *Align,
Decl *New) {
191 llvm::APInt(64, Align->getParamIndex().getSourceIndex()),
198 const AnnotateAttr *
Attr,
Decl *New) {
204 bool HasDelayedArgs =
Attr->delayedArgs_size();
213 false, TemplateArgs, Args))
216 StringRef Str =
Attr->getAnnotation();
217 if (HasDelayedArgs) {
218 if (Args.size() < 1) {
228 ActualArgs.insert(ActualArgs.begin(), Args.begin() + 1, Args.end());
229 std::swap(Args, ActualArgs);
237 Expr *Cond =
nullptr;
251 Cond = Converted.
get();
257 S.
Diag(A->
getLocation(), diag::err_attr_cond_never_constant_expr) << A;
258 for (
const auto &
P : Diags)
259 S.
Diag(
P.first,
P.second);
269 S, TemplateArgs, EIA, EIA->getCond(), Tmpl, New);
273 Cond, EIA->getMessage()));
280 S, TemplateArgs, DIA, DIA->getCond(), Tmpl, New);
285 DIA->getDiagnosticType(), DIA->getArgDependent(), New));
292 const CUDALaunchBoundsAttr &
Attr,
Decl *New) {
302 Expr *MinBlocks =
nullptr;
303 if (
Attr.getMinBlocks()) {
310 Expr *MaxBlocks =
nullptr;
311 if (
Attr.getMaxBlocks()) {
332 const OMPDeclareSimdDeclAttr &
Attr,
Decl *New) {
334 if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(New))
335 New = FTD->getTemplatedDecl();
336 auto *FD = cast<FunctionDecl>(New);
337 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(FD->getDeclContext());
343 if (
auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
346 if (FD->getNumParams() > PVD->getFunctionScopeIndex())
347 Local.InstantiatedLocal(
348 PVD, FD->getParamDecl(PVD->getFunctionScopeIndex()));
352 FD->isCXXInstanceMember());
368 if (
auto *
E =
Attr.getSimdlen())
371 if (
Attr.uniforms_size() > 0) {
372 for(
auto *
E :
Attr.uniforms()) {
376 Uniforms.push_back(Inst.
get());
380 auto AI =
Attr.alignments_begin();
381 for (
auto *
E :
Attr.aligneds()) {
385 Aligneds.push_back(Inst.
get());
389 Alignments.push_back(Inst.
get());
393 auto SI =
Attr.steps_begin();
394 for (
auto *
E :
Attr.linears()) {
398 Linears.push_back(Inst.
get());
402 Steps.push_back(Inst.
get());
405 LinModifiers.append(
Attr.modifiers_begin(),
Attr.modifiers_end());
408 Uniforms, Aligneds, Alignments, Linears, LinModifiers, Steps,
415 const OMPDeclareVariantAttr &
Attr,
Decl *New) {
417 if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(New))
418 New = FTD->getTemplatedDecl();
419 auto *FD = cast<FunctionDecl>(New);
420 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(FD->getDeclContext());
422 auto &&SubstExpr = [FD, ThisContext, &S, &TemplateArgs](
Expr *
E) {
424 if (
auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
427 if (FD->getNumParams() > PVD->getFunctionScopeIndex())
428 Local.InstantiatedLocal(
429 PVD, FD->getParamDecl(PVD->getFunctionScopeIndex()));
433 FD->isCXXInstanceMember());
439 auto &&Subst = [&SubstExpr, &S](
Expr *
E) {
449 if (
Expr *
E =
Attr.getVariantFuncRef()) {
454 VariantFuncRef = Subst(
E);
460 TI = *
Attr.getTraitInfos();
463 auto SubstScoreOrConditionExpr = [&S, Subst](
Expr *&
E,
bool) {
482 std::optional<std::pair<FunctionDecl *, Expr *>> DeclVarData =
490 E = DeclVarData->second;
491 FD = DeclVarData->first;
494 if (
auto *VariantFD = dyn_cast<FunctionDecl>(VariantDRE->getDecl())) {
495 if (
auto *VariantFTD = VariantFD->getDescribedFunctionTemplate()) {
496 if (!VariantFTD->isThisDeclarationADefinition())
507 SubstFD->getType(), FD->getType(),
515 SubstFD->setInstantiationIsPending(!SubstFD->isDefined());
519 SubstFD->getLocation(),
529 for (
Expr *
E :
Attr.adjustArgsNothing()) {
533 NothingExprs.push_back(ER.
get());
535 for (
Expr *
E :
Attr.adjustArgsNeedDevicePtr()) {
539 NeedDevicePtrExprs.push_back(ER.
get());
543 AppendArgs.emplace_back(II.IsTarget, II.IsTargetSync);
547 FD,
E, TI, NothingExprs, NeedDevicePtrExprs, AppendArgs,
SourceLocation(),
553 const AMDGPUFlatWorkGroupSizeAttr &
Attr,
Decl *New) {
576 Expr *Cond =
nullptr;
584 Cond = SubstResult.
get();
594 const AMDGPUWavesPerEUAttr &
Attr,
Decl *New) {
604 Expr *MaxExpr =
nullptr;
605 if (
auto Max =
Attr.getMax()) {
617 const AMDGPUMaxNumWorkGroupsAttr &
Attr,
Decl *New) {
643 const SYCLKernelAttr &
Attr,
Decl *New) {
653 if (
const auto *PNA = dyn_cast<PreferredNameAttr>(A)) {
655 const auto *RD = cast<CXXRecordDecl>(
D);
661 PNA->getTypedefType()))
666 if (
const auto *BA = dyn_cast<BuiltinAttr>(A)) {
668 switch (BA->getID()) {
669 case Builtin::BIforward:
679 case Builtin::BImove:
680 case Builtin::BImove_if_noexcept:
696 const HLSLParamModifierAttr *
Attr,
Decl *New) {
706 if (
NamedDecl *ND = dyn_cast<NamedDecl>(New)) {
710 for (
const auto *TmplAttr : Tmpl->
attrs()) {
717 *
this, dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()),
721 TmplAttr,
Context, *
this, TemplateArgs);
731 case clang::attr::CFConsumed:
733 case clang::attr::OSConsumed:
735 case clang::attr::NSConsumed:
738 llvm_unreachable(
"Wrong argument supplied");
746 for (
const auto *TmplAttr : Tmpl->
attrs()) {
751 const AlignedAttr *Aligned = dyn_cast<AlignedAttr>(TmplAttr);
752 if (Aligned && Aligned->isAlignmentDependent()) {
757 if (
const auto *AssumeAligned = dyn_cast<AssumeAlignedAttr>(TmplAttr)) {
762 if (
const auto *AlignValue = dyn_cast<AlignValueAttr>(TmplAttr)) {
767 if (
const auto *AllocAlign = dyn_cast<AllocAlignAttr>(TmplAttr)) {
772 if (
const auto *Annotate = dyn_cast<AnnotateAttr>(TmplAttr)) {
777 if (
const auto *EnableIf = dyn_cast<EnableIfAttr>(TmplAttr)) {
779 cast<FunctionDecl>(New));
783 if (
const auto *DiagnoseIf = dyn_cast<DiagnoseIfAttr>(TmplAttr)) {
785 cast<FunctionDecl>(New));
789 if (
const auto *CUDALaunchBounds =
790 dyn_cast<CUDALaunchBoundsAttr>(TmplAttr)) {
792 *CUDALaunchBounds, New);
796 if (
const auto *Mode = dyn_cast<ModeAttr>(TmplAttr)) {
801 if (
const auto *OMPAttr = dyn_cast<OMPDeclareSimdDeclAttr>(TmplAttr)) {
806 if (
const auto *OMPAttr = dyn_cast<OMPDeclareVariantAttr>(TmplAttr)) {
811 if (
const auto *AMDGPUFlatWorkGroupSize =
812 dyn_cast<AMDGPUFlatWorkGroupSizeAttr>(TmplAttr)) {
814 *
this, TemplateArgs, *AMDGPUFlatWorkGroupSize, New);
817 if (
const auto *AMDGPUFlatWorkGroupSize =
818 dyn_cast<AMDGPUWavesPerEUAttr>(TmplAttr)) {
820 *AMDGPUFlatWorkGroupSize, New);
823 if (
const auto *AMDGPUMaxNumWorkGroups =
824 dyn_cast<AMDGPUMaxNumWorkGroupsAttr>(TmplAttr)) {
826 *
this, TemplateArgs, *AMDGPUMaxNumWorkGroups, New);
829 if (
const auto *ParamAttr = dyn_cast<HLSLParamModifierAttr>(TmplAttr)) {
836 if (TmplAttr->getKind() == attr::DLLExport ||
837 TmplAttr->getKind() == attr::DLLImport) {
838 if (New->
hasAttr<DLLExportAttr>() || New->
hasAttr<DLLImportAttr>()) {
843 if (
const auto *ABIAttr = dyn_cast<ParameterABIAttr>(TmplAttr)) {
848 if (isa<NSConsumedAttr>(TmplAttr) || isa<OSConsumedAttr>(TmplAttr) ||
849 isa<CFConsumedAttr>(TmplAttr)) {
856 if (
auto *A = dyn_cast<PointerAttr>(TmplAttr)) {
857 if (!New->
hasAttr<PointerAttr>())
862 if (
auto *A = dyn_cast<OwnerAttr>(TmplAttr)) {
863 if (!New->
hasAttr<OwnerAttr>())
868 if (
auto *A = dyn_cast<SYCLKernelAttr>(TmplAttr)) {
873 assert(!TmplAttr->isPackExpansion());
874 if (TmplAttr->isLateParsed() && LateAttrs) {
883 auto *ND = cast<NamedDecl>(New);
884 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
886 ND->isCXXInstanceMember());
889 *
this, TemplateArgs);
897 for (
const auto *
Attr : Pattern->
attrs()) {
898 if (
auto *A = dyn_cast<StrictFPAttr>(
Attr)) {
899 if (!Inst->
hasAttr<StrictFPAttr>())
912 DLLExportAttr *
Attr = Ctor->
getAttr<DLLExportAttr>();
915 for (
unsigned I = 0; I != NumParams; ++I) {
926template<
typename DeclT>
942 llvm_unreachable(
"Translation units cannot be instantiated");
946 llvm_unreachable(
"HLSL buffer declarations cannot be instantiated");
951 llvm_unreachable(
"pragma comment cannot be instantiated");
954Decl *TemplateDeclInstantiator::VisitPragmaDetectMismatchDecl(
956 llvm_unreachable(
"pragma comment cannot be instantiated");
961 llvm_unreachable(
"extern \"C\" context cannot be instantiated");
965 llvm_unreachable(
"GUID declaration cannot be instantiated");
968Decl *TemplateDeclInstantiator::VisitUnnamedGlobalConstantDecl(
970 llvm_unreachable(
"UnnamedGlobalConstantDecl cannot be instantiated");
973Decl *TemplateDeclInstantiator::VisitTemplateParamObjectDecl(
975 llvm_unreachable(
"template parameter objects cannot be instantiated");
979TemplateDeclInstantiator::VisitLabelDecl(
LabelDecl *
D) {
988 llvm_unreachable(
"Namespaces cannot be instantiated");
995 D->getNamespaceLoc(),
998 D->getQualifierLoc(),
999 D->getTargetNameLoc(),
1011 DI = SemaRef.
SubstType(DI, TemplateArgs,
1032 D->getIdentifier() &&
D->getIdentifier()->isStr(
"type") &&
1051 if (
const TagType *oldTagType =
D->getUnderlyingType()->getAs<
TagType>()) {
1052 TagDecl *oldTag = oldTagType->getDecl();
1122 if (getPreviousDeclForInstantiation<TypedefNameDecl>(Pattern)) {
1124 if (!
Found.empty()) {
1125 PrevAliasTemplate = dyn_cast<TypeAliasTemplateDecl>(
Found.front());
1136 D->getDeclName(), InstParams, AliasInst);
1138 if (PrevAliasTemplate)
1143 if (!PrevAliasTemplate)
1160 D->getIdentifier());
1169 for (
auto *OldBD :
D->bindings())
1170 NewBindings.push_back(cast<BindingDecl>(VisitBindingDecl(OldBD)));
1173 auto *NewDD = cast_or_null<DecompositionDecl>(
1176 if (!NewDD || NewDD->isInvalidDecl())
1177 for (
auto *NewBD : NewBindings)
1178 NewBD->setInvalidDecl();
1188 bool InstantiatingVarTemplate,
1193 D->getTypeSourceInfo(), TemplateArgs,
D->getTypeSpecStartLoc(),
1194 D->getDeclName(),
true);
1199 SemaRef.
Diag(
D->
getLocation(), diag::err_variable_instantiates_to_function)
1200 <<
D->isStaticDataMember() << DI->
getType();
1217 DI,
D->getStorageClass());
1232 StartingScope, InstantiatingVarTemplate);
1235 if (
auto *F = dyn_cast<FunctionDecl>(DC))
1236 RT = F->getReturnType();
1237 else if (isa<BlockDecl>(DC))
1241 llvm_unreachable(
"Unknown context type");
1273 D->getAccessSpecifierLoc(),
D->getColonLoc());
1283 DI = SemaRef.
SubstType(DI, TemplateArgs,
1286 DI =
D->getTypeSourceInfo();
1303 Expr *BitWidth =
D->getBitWidth();
1306 else if (BitWidth) {
1312 = SemaRef.
SubstExpr(BitWidth, TemplateArgs);
1317 BitWidth = InstantiatedBitWidth.
getAs<
Expr>();
1322 cast<RecordDecl>(Owner),
1326 D->getInClassInitStyle(),
1327 D->getInnerLocStart(),
1337 if (
Field->hasAttrs())
1341 Field->setInvalidDecl();
1343 if (!
Field->getDeclName()) {
1348 if (
Parent->isAnonymousStructOrUnion() &&
1349 Parent->getRedeclContext()->isFunctionOrMethod())
1369 DI = SemaRef.
SubstType(DI, TemplateArgs,
1372 DI =
D->getTypeSourceInfo();
1410 for (
auto *PI :
D->chain()) {
1416 NamedChain[i++] = Next;
1419 QualType T = cast<FieldDecl>(NamedChain[i-1])->getType();
1422 {NamedChain, D->getChainingSize()});
1429 Owner->
addDecl(IndirectField);
1430 return IndirectField;
1442 if (
D->isUnsupportedFriend()) {
1445 InstTy = SemaRef.
SubstType(Ty, TemplateArgs,
1460 assert(ND &&
"friend decl must be a decl or a type!");
1467 if (!NewND)
return nullptr;
1471 cast<NamedDecl>(NewND),
D->getFriendLoc());
1479 Expr *AssertExpr =
D->getAssertExpr();
1486 = SemaRef.
SubstExpr(AssertExpr, TemplateArgs);
1491 SemaRef.
SubstExpr(
D->getMessage(), TemplateArgs);
1492 if (InstantiatedMessageExpr.
isInvalid())
1497 InstantiatedMessageExpr.
get(),
D->getRParenLoc(),
D->isFailed());
1506 if (!Prev)
return nullptr;
1507 PrevDecl = cast<EnumDecl>(Prev);
1513 D->isScoped(),
D->isScopedUsingClassTag(),
D->isFixed());
1525 Enum->setIntegerTypeSourceInfo(NewTI);
1527 assert(!
D->getIntegerType()->isDependentType()
1528 &&
"Dependent type without type source info");
1529 Enum->setIntegerType(
D->getIntegerType());
1551 if (Def && Def !=
D) {
1558 SemaRef.
SubstType(TI->getType(), TemplateArgs,
1561 DefnUnderlying,
true,
Enum);
1582 Enum->startDefinition();
1593 if (
Expr *UninstValue = EC->getInitExpr()) {
1603 if (
Value.isInvalid()) {
1616 Enum->setInvalidDecl();
1623 Enum->addDecl(EnumConst);
1624 Enumerators.push_back(EnumConst);
1625 LastEnumConst = EnumConst;
1628 !
Enum->isScoped()) {
1641 llvm_unreachable(
"EnumConstantDecls can only occur within EnumDecls.");
1646 llvm_unreachable(
"BuiltinTemplateDecls cannot be instantiated.");
1678 if (!
Found.empty()) {
1679 PrevClassTemplate = dyn_cast<ClassTemplateDecl>(
Found.front());
1680 if (PrevClassTemplate)
1693 SS.
Adopt(QualifierLoc);
1695 if (!DC)
return nullptr;
1709 if (R.isSingleResult()) {
1711 if (PrevClassTemplate)
1715 if (!PrevClassTemplate && QualifierLoc) {
1717 << llvm::to_underlying(
D->getTemplatedDecl()->getTagKind())
1735 D->getIdentifier(), InstParams, RecordInst);
1744 if (PrevClassTemplate) {
1775 if (!PrevClassTemplate)
1798 if (!PrevClassTemplate) {
1803 D->getPartialSpecializations(PartialSpecs);
1804 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
1805 if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())
1806 OutOfLinePartialSpecs.push_back(std::make_pair(Inst, PartialSpecs[I]));
1813TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl(
1825 = dyn_cast<ClassTemplateDecl>(
Found.front());
1826 if (!InstClassTemplate)
1837 assert(
D->getTemplatedDecl()->isStaticDataMember() &&
1838 "Only static data member templates are allowed.");
1848 VarDecl *Pattern =
D->getTemplatedDecl();
1854 PrevVarTemplate = dyn_cast<VarTemplateDecl>(
Found.front());
1860 if (!VarInst)
return nullptr;
1871 if (!PrevVarTemplate)
1881 if (!PrevVarTemplate) {
1886 D->getPartialSpecializations(PartialSpecs);
1887 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
1888 if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())
1889 OutOfLineVarPartialSpecs.push_back(
1890 std::make_pair(Inst, PartialSpecs[I]));
1896Decl *TemplateDeclInstantiator::VisitVarTemplatePartialSpecializationDecl(
1898 assert(
D->isStaticDataMember() &&
1899 "Only static data member templates are allowed.");
1905 assert(!
Found.empty() &&
"Instantiation found nothing?");
1908 assert(InstVarTemplate &&
"Instantiation did not find a variable template?");
1932 if (
CXXMethodDecl *DMethod = dyn_cast<CXXMethodDecl>(
D->getTemplatedDecl()))
1937 D->getTemplatedDecl(),
1948 assert(InstTemplate &&
1949 "VisitFunctionDecl/CXXMethodDecl didn't create a template!");
1956 !(isFriend && !
D->getTemplatedDecl()->isThisDeclarationADefinition()))
1967 return InstTemplate;
1976 if (!Prev)
return nullptr;
1977 PrevDecl = cast<CXXRecordDecl>(Prev);
1981 bool IsInjectedClassName =
D->isInjectedClassName();
1985 D->getLambdaDependencyKind(),
D->isGenericLambda(),
1986 D->getLambdaCaptureDefault());
1990 D->getIdentifier(), PrevDecl,
1991 IsInjectedClassName);
1993 if (IsInjectedClassName)
2009 if (!IsInjectedClassName)
2015 Record->setObjectOfFriendDecl();
2018 if (
D->isAnonymousStructOrUnion())
2019 Record->setAnonymousStructOrUnion(
true);
2021 if (
D->isLocalClass())
2042 if (
D->isCompleteDefinition() &&
D->isLocalClass()) {
2051 if (!
D->isCXXClassMember())
2057 LocalInstantiations.perform();
2062 if (IsInjectedClassName)
2063 assert(
Record->isInjectedClassName() &&
"Broken injected-class-name");
2081 if (OrigFunc->
getExtInfo() == NewFunc->getExtInfo())
2087 NewFunc->getParamTypes(), NewEPI);
2101 if (FunctionTemplate && !TemplateParams) {
2104 void *InsertPos =
nullptr;
2114 if (FunctionTemplate)
2119 bool MergeWithParentScope = (TemplateParams !=
nullptr) ||
2121 !(isa<Decl>(Owner) &&
2122 cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
2126 if (
auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(
D)) {
2128 TemplateArgs, DGuide->getExplicitSpecifier());
2129 if (InstantiatedExplicitSpecifier.
isInvalid())
2139 if (TemplateParams && TemplateParams->
size()) {
2141 dyn_cast<TemplateTypeParmDecl>(TemplateParams->
asArray().back());
2142 if (LastParam && LastParam->isImplicit() &&
2143 LastParam->hasTypeConstraint()) {
2164 Expr *TrailingRequiresClause =
D->getTrailingRequiresClause();
2173 }
else if (isFriend && QualifierLoc) {
2175 SS.
Adopt(QualifierLoc);
2177 if (!DC)
return nullptr;
2190 if (
auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(
D)) {
2192 SemaRef.
Context, DC,
D->getInnerLocStart(),
2193 InstantiatedExplicitSpecifier, NameInfo,
T, TInfo,
2195 DGuide->getDeductionCandidateKind());
2199 SemaRef.
Context, DC,
D->getInnerLocStart(), NameInfo,
T, TInfo,
2201 D->isInlineSpecified(),
D->hasWrittenPrototype(),
D->getConstexprKind(),
2202 TrailingRequiresClause);
2203 Function->setFriendConstraintRefersToEnclosingTemplate(
2204 D->FriendConstraintRefersToEnclosingTemplate());
2212 Function->setQualifierInfo(QualifierLoc);
2226 Function->setLexicalDeclContext(LexicalDC);
2229 for (
unsigned P = 0;
P < Params.size(); ++
P)
2234 if (TrailingRequiresClause)
2235 Function->setTrailingRequiresClause(TrailingRequiresClause);
2237 if (TemplateParams) {
2256 Function->setDescribedFunctionTemplate(FunctionTemplate);
2260 if (isFriend &&
D->isThisDeclarationADefinition()) {
2262 D->getDescribedFunctionTemplate());
2264 }
else if (FunctionTemplate &&
2269 Function->setFunctionTemplateSpecialization(FunctionTemplate,
2274 if (isFriend &&
D->isThisDeclarationADefinition()) {
2279 }
else if (!isFriend) {
2290 FT->setObjectOfFriendDecl();
2296 bool IsExplicitSpecialization =
false;
2306 D->getDependentSpecializationInfo()) {
2307 assert(isFriend &&
"dependent specialization info on "
2308 "non-member non-friend function?");
2312 if (
const auto *ArgsWritten = DFTSI->TemplateArgumentsAsWritten) {
2313 ExplicitArgs.
setLAngleLoc(ArgsWritten->getLAngleLoc());
2314 ExplicitArgs.
setRAngleLoc(ArgsWritten->getRAngleLoc());
2331 DFTSI->TemplateArgumentsAsWritten ? &ExplicitArgs :
nullptr,
2335 IsExplicitSpecialization =
true;
2337 D->getTemplateSpecializationArgsAsWritten()) {
2343 ArgsWritten->getRAngleLoc());
2353 IsExplicitSpecialization =
true;
2354 }
else if (TemplateParams || !FunctionTemplate) {
2370 if (isFriend && !QualifierLoc) {
2390 if (
Function->isLocalExternDecl()) {
2392 if (!PVD->hasDefaultArg())
2398 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
2401 { UninstExpr }, UninstExpr->
getType());
2403 PVD->setDefaultArg(ErrorResult.
get());
2409 IsExplicitSpecialization,
2410 Function->isThisDeclarationADefinition());
2416 if (isFriend && TemplateParams && FunctionTemplate->
getPreviousDecl()) {
2420 Function->isThisDeclarationADefinition()
2429 if (isFriend &&
D->isThisDeclarationADefinition() &&
Function->isUsed(
false)) {
2431 Function->getMemberSpecializationInfo()) {
2432 if (MSInfo->getPointOfInstantiation().isInvalid()) {
2434 MSInfo->setPointOfInstantiation(
Loc);
2441 if (
D->isExplicitlyDefaulted()) {
2449 (TemplateParams ? cast<NamedDecl>(FunctionTemplate) :
Function);
2468 if (FunctionTemplate && !TemplateParams) {
2474 void *InsertPos =
nullptr;
2484 if (FunctionTemplate)
2489 bool MergeWithParentScope = (TemplateParams !=
nullptr) ||
2490 !(isa<Decl>(Owner) &&
2491 cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
2499 unsigned NumTempParamLists = 0;
2500 if (isFriend && (NumTempParamLists =
D->getNumTemplateParameterLists())) {
2501 TempParamLists.resize(NumTempParamLists);
2502 for (
unsigned I = 0; I != NumTempParamLists; ++I) {
2507 TempParamLists[I] = InstParams;
2513 const bool CouldInstantiate =
2514 InstantiatedExplicitSpecifier.getExpr() ==
nullptr ||
2515 !InstantiatedExplicitSpecifier.getExpr()->isValueDependent();
2519 if (CouldInstantiate ||
2523 TemplateArgs, InstantiatedExplicitSpecifier);
2525 if (InstantiatedExplicitSpecifier.isInvalid())
2537 if (cast<CXXRecordDecl>(
D->getParent())->isLambda() &&
2538 !
D->getTypeSourceInfo() &&
2539 isa<CXXConstructorDecl, CXXDestructorDecl>(
D)) {
2542 D->setTypeSourceInfo(TSI);
2551 if (TemplateParams && TemplateParams->
size()) {
2553 dyn_cast<TemplateTypeParmDecl>(TemplateParams->
asArray().back());
2554 if (LastParam && LastParam->isImplicit() &&
2555 LastParam->hasTypeConstraint()) {
2580 SS.
Adopt(QualifierLoc);
2590 if (!DC)
return nullptr;
2594 Expr *TrailingRequiresClause =
D->getTrailingRequiresClause();
2609 InstantiatedExplicitSpecifier, Constructor->UsesFPIntrin(),
2610 Constructor->isInlineSpecified(),
false,
2612 TrailingRequiresClause);
2618 Destructor->getConstexprKind(), TrailingRequiresClause);
2627 Conversion->UsesFPIntrin(), Conversion->isInlineSpecified(),
2628 InstantiatedExplicitSpecifier, Conversion->getConstexprKind(),
2629 Conversion->getEndLoc(), TrailingRequiresClause);
2634 D->UsesFPIntrin(),
D->isInlineSpecified(),
D->getConstexprKind(),
2644 if (TemplateParams) {
2661 TemplateParams, Method);
2668 }
else if (FunctionTemplate) {
2684 if (NumTempParamLists)
2695 for (
unsigned P = 0;
P < Params.size(); ++
P)
2696 Params[
P]->setOwningFunction(Method);
2703 RedeclarationKind::ForExternalRedeclaration);
2705 bool IsExplicitSpecialization =
false;
2710 D->getDependentSpecializationInfo()) {
2713 if (
const auto *ArgsWritten = DFTSI->TemplateArgumentsAsWritten) {
2714 ExplicitArgs.
setLAngleLoc(ArgsWritten->getLAngleLoc());
2715 ExplicitArgs.
setRAngleLoc(ArgsWritten->getRAngleLoc());
2731 Method, DFTSI->TemplateArgumentsAsWritten ? &ExplicitArgs :
nullptr,
2735 IsExplicitSpecialization =
true;
2737 D->getTemplateSpecializationArgsAsWritten()) {
2741 ArgsWritten->getRAngleLoc());
2752 IsExplicitSpecialization =
true;
2753 }
else if (!FunctionTemplate || TemplateParams || isFriend) {
2780 for (
unsigned P = 0;
P < Params.size(); ++
P) {
2781 if (!Params[
P]->hasDefaultArg())
2787 Expr *UninstExpr = Params[
P]->getUninstantiatedDefaultArg();
2790 { UninstExpr }, UninstExpr->
getType());
2792 Params[
P]->setDefaultArg(ErrorResult.
get());
2798 IsExplicitSpecialization,
2801 if (
D->isPureVirtual())
2811 if (FunctionTemplate)
2817 if (
D->isExplicitlyDefaulted()) {
2821 if (
D->isDeletedAsWritten())
2823 D->getDeletedMessage());
2828 if (IsExplicitSpecialization && !isFriend)
2838 if (
auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
2839 if (Constructor->isDefaultConstructor() ||
2840 Constructor->isCopyOrMoveConstructor())
2848 if (FunctionTemplate) {
2856 }
else if (isFriend) {
2862 Record->makeDeclVisibleInContext(Method);
2873 if (Method->
hasAttr<UsedAttr>()) {
2874 if (
const auto *A = dyn_cast<CXXRecordDecl>(Owner)) {
2877 A->getMemberSpecializationInfo())
2878 Loc = MSInfo->getPointOfInstantiation();
2879 else if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A))
2880 Loc = Spec->getPointOfInstantiation();
2906Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl(
2908 assert(
D->getTypeForDecl()->isTemplateTypeParmType());
2910 std::optional<unsigned> NumExpanded;
2913 if (
D->isPackExpansion() && !
D->isExpandedParameterPack()) {
2914 assert(TC->getTemplateArgsAsWritten() &&
2915 "type parameter can only be an expansion when explicit arguments "
2921 for (
auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
2927 bool RetainExpansion =
false;
2929 cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
2932 TC->hasExplicitTemplateArgs() ?
2933 TC->getTemplateArgsAsWritten()->getRAngleLoc() :
2934 TC->getConceptNameInfo().getEndLoc()),
2935 Unexpanded, TemplateArgs, Expand, RetainExpansion, NumExpanded))
2944 D->hasTypeConstraint(), NumExpanded);
2948 if (
auto *TC =
D->getTypeConstraint()) {
2954 EvaluateConstraints))
2958 if (
D->hasDefaultArgument() && !
D->defaultArgumentWasInherited()) {
2972Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
2975 TypeLoc TL =
D->getTypeSourceInfo()->getTypeLoc();
2978 bool IsExpandedParameterPack =
false;
2983 if (
D->isExpandedParameterPack()) {
2986 ExpandedParameterPackTypes.reserve(
D->getNumExpansionTypes());
2987 ExpandedParameterPackTypesAsWritten.reserve(
D->getNumExpansionTypes());
2988 for (
unsigned I = 0, N =
D->getNumExpansionTypes(); I != N; ++I) {
2990 SemaRef.
SubstType(
D->getExpansionTypeSourceInfo(I), TemplateArgs,
3000 ExpandedParameterPackTypesAsWritten.push_back(NewDI);
3001 ExpandedParameterPackTypes.push_back(NewT);
3004 IsExpandedParameterPack =
true;
3005 DI =
D->getTypeSourceInfo();
3007 }
else if (
D->isPackExpansion()) {
3019 bool RetainExpansion =
false;
3020 std::optional<unsigned> OrigNumExpansions =
3022 std::optional<unsigned> NumExpansions = OrigNumExpansions;
3024 Pattern.getSourceRange(),
3027 Expand, RetainExpansion,
3032 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3045 ExpandedParameterPackTypesAsWritten.push_back(NewDI);
3046 ExpandedParameterPackTypes.push_back(NewT);
3052 IsExpandedParameterPack =
true;
3053 DI =
D->getTypeSourceInfo();
3075 DI = SemaRef.
SubstType(
D->getTypeSourceInfo(), TemplateArgs,
3089 if (IsExpandedParameterPack)
3093 D->getPosition(),
D->getIdentifier(),
T, DI, ExpandedParameterPackTypes,
3094 ExpandedParameterPackTypesAsWritten);
3102 if (AutoLoc.isConstrained()) {
3104 if (IsExpandedParameterPack)
3107 else if (
auto *Constraint = dyn_cast_if_present<CXXFoldExpr>(
3108 D->getPlaceholderTypeConstraint()))
3109 EllipsisLoc = Constraint->getEllipsisLoc();
3123 if (
D->hasDefaultArgument() && !
D->defaultArgumentWasInherited()) {
3142 for (
const auto &
P : *Params) {
3143 if (
P->isTemplateParameterPack())
3155TemplateDeclInstantiator::VisitTemplateTemplateParmDecl(
3162 bool IsExpandedParameterPack =
false;
3164 if (
D->isExpandedParameterPack()) {
3168 ExpandedParams.reserve(
D->getNumExpansionTemplateParameters());
3169 for (
unsigned I = 0, N =
D->getNumExpansionTemplateParameters();
3176 ExpandedParams.push_back(Expansion);
3179 IsExpandedParameterPack =
true;
3180 InstParams = TempParams;
3181 }
else if (
D->isPackExpansion()) {
3192 bool RetainExpansion =
false;
3193 std::optional<unsigned> NumExpansions;
3198 Expand, RetainExpansion,
3203 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3209 ExpandedParams.push_back(Expansion);
3215 IsExpandedParameterPack =
true;
3216 InstParams = TempParams;
3238 if (IsExpandedParameterPack)
3242 D->getPosition(),
D->getIdentifier(),
D->wasDeclaredWithTypename(),
3243 InstParams, ExpandedParams);
3249 D->wasDeclaredWithTypename(), InstParams);
3250 if (
D->hasDefaultArgument() && !
D->defaultArgumentWasInherited()) {
3252 D->getDefaultArgument().getTemplateQualifierLoc();
3256 QualifierLoc,
D->getDefaultArgument().getArgument().getAsTemplate(),
3257 D->getDefaultArgument().getTemplateNameLoc(), TemplateArgs);
3262 D->getDefaultArgument().getTemplateQualifierLoc(),
3263 D->getDefaultArgument().getTemplateNameLoc()));
3281 D->getNamespaceKeyLocation(),
3282 D->getQualifierLoc(),
3283 D->getIdentLocation(),
3284 D->getNominatedNamespace(),
3285 D->getCommonAncestor());
3301 for (
auto *Shadow :
D->shadows()) {
3305 NamedDecl *OldTarget = Shadow->getTargetDecl();
3306 if (
auto *CUSD = dyn_cast<ConstructorUsingShadowDecl>(Shadow))
3307 if (
auto *BaseShadow = CUSD->getNominatedBaseClassShadowDecl())
3308 OldTarget = BaseShadow;
3312 dyn_cast<UnresolvedUsingIfExistsDecl>(Shadow->getTargetDecl())) {
3314 SemaRef.
Context, Owner, EmptyD->getLocation(), EmptyD->getDeclName());
3317 Shadow->getLocation(), OldTarget, TemplateArgs));
3329 Shadow->getLocation(), OldPrev, TemplateArgs));
3332 nullptr, Inst, InstTarget, PrevDecl);
3335 if (isFunctionScope)
3363 if (
auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.
CurContext))
3369 bool CheckRedeclaration = Owner->
isRecord();
3371 RedeclarationKind::ForVisibleRedeclaration);
3380 SS.
Adopt(QualifierLoc);
3381 if (CheckRedeclaration) {
3382 Prev.setHideTags(
false);
3387 D->hasTypename(), SS,
3451Decl *TemplateDeclInstantiator::VisitConstructorUsingShadowDecl(
3457template <
typename T>
3458Decl *TemplateDeclInstantiator::instantiateUnresolvedUsingDecl(
3459 T *
D,
bool InstantiatingPackElement) {
3461 if (
D->isPackExpansion() && !InstantiatingPackElement) {
3469 bool RetainExpansion =
false;
3470 std::optional<unsigned> NumExpansions;
3473 Expand, RetainExpansion, NumExpansions))
3478 assert(!RetainExpansion &&
3479 "should never need to retain an expansion for UsingPackDecl");
3485 return instantiateUnresolvedUsingDecl(
D,
true);
3496 SemaRef.
Diag(
D->getEllipsisLoc(),
3497 diag::err_using_decl_redeclaration_expansion);
3503 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3505 Decl *Slice = instantiateUnresolvedUsingDecl(
D,
true);
3512 Expansions.push_back(cast<NamedDecl>(Slice));
3531 SS.
Adopt(QualifierLoc);
3538 bool InstantiatingSlice =
D->getEllipsisLoc().isValid() &&
3543 bool IsUsingIfExists =
D->template hasAttr<UsingIfExistsAttr>();
3546 TD, TypenameLoc, SS, NameInfo, EllipsisLoc,
3548 true, IsUsingIfExists);
3557Decl *TemplateDeclInstantiator::VisitUnresolvedUsingTypenameDecl(
3559 return instantiateUnresolvedUsingDecl(
D);
3562Decl *TemplateDeclInstantiator::VisitUnresolvedUsingValueDecl(
3564 return instantiateUnresolvedUsingDecl(
D);
3567Decl *TemplateDeclInstantiator::VisitUnresolvedUsingIfExistsDecl(
3569 llvm_unreachable(
"referring to unresolved decl out of UsingShadowDecl");
3574 for (
auto *UD :
D->expansions()) {
3577 Expansions.push_back(NewUD);
3588Decl *TemplateDeclInstantiator::VisitOMPThreadPrivateDecl(
3591 for (
auto *I :
D->varlist()) {
3593 assert(isa<DeclRefExpr>(Var) &&
"threadprivate arg is not a DeclRefExpr");
3594 Vars.push_back(Var);
3608 for (
auto *I :
D->varlist()) {
3610 assert(isa<DeclRefExpr>(Var) &&
"allocate arg is not a DeclRefExpr");
3611 Vars.push_back(Var);
3617 if (
auto *AC = dyn_cast<OMPAllocatorClause>(
C)) {
3622 NewE.
get(), AC->getBeginLoc(), AC->getLParenLoc(), AC->getEndLoc());
3623 }
else if (
auto *AC = dyn_cast<OMPAlignClause>(
C)) {
3628 NewE.
get(), AC->getBeginLoc(), AC->getLParenLoc(), AC->getEndLoc());
3633 Clauses.push_back(IC);
3638 if (Res.
get().isNull())
3640 return Res.
get().getSingleDecl();
3645 "Requires directive cannot be instantiated within a dependent context");
3648Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl(
3651 const bool RequiresInstantiation =
3652 D->getType()->isDependentType() ||
3653 D->getType()->isInstantiationDependentType() ||
3654 D->getType()->containsUnexpandedParameterPack();
3656 if (RequiresInstantiation) {
3662 SubstReductionType =
D->getType();
3664 if (SubstReductionType.
isNull())
3666 Expr *Combiner =
D->getCombiner();
3668 bool IsCorrect =
true;
3670 std::pair<QualType, SourceLocation> ReductionTypes[] = {
3672 auto *PrevDeclInScope =
D->getPrevDeclInScope();
3673 if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) {
3674 PrevDeclInScope = cast<OMPDeclareReductionDecl>(
3679 nullptr, Owner,
D->getDeclName(), ReductionTypes,
D->
getAccess(),
3681 auto *NewDRD = cast<OMPDeclareReductionDecl>(DRD.get().getSingleDecl());
3683 Expr *SubstCombiner =
nullptr;
3684 Expr *SubstInitializer =
nullptr;
3690 cast<DeclRefExpr>(
D->getCombinerIn())->getDecl(),
3691 cast<DeclRefExpr>(NewDRD->getCombinerIn())->getDecl());
3693 cast<DeclRefExpr>(
D->getCombinerOut())->getDecl(),
3694 cast<DeclRefExpr>(NewDRD->getCombinerOut())->getDecl());
3695 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(Owner);
3698 SubstCombiner = SemaRef.
SubstExpr(Combiner, TemplateArgs).
get();
3708 cast<DeclRefExpr>(
D->getInitOrig())->getDecl(),
3709 cast<DeclRefExpr>(NewDRD->getInitOrig())->getDecl());
3711 cast<DeclRefExpr>(
D->getInitPriv())->getDecl(),
3712 cast<DeclRefExpr>(NewDRD->getInitPriv())->getDecl());
3717 cast<VarDecl>(cast<DeclRefExpr>(
D->getInitPriv())->getDecl());
3718 IsCorrect = IsCorrect && OldPrivParm->hasInit();
3724 NewDRD, SubstInitializer, OmpPrivParm);
3726 IsCorrect = IsCorrect && SubstCombiner &&
3729 SubstInitializer) ||
3731 !SubstInitializer));
3742 const bool RequiresInstantiation =
3743 D->getType()->isDependentType() ||
3744 D->getType()->isInstantiationDependentType() ||
3745 D->getType()->containsUnexpandedParameterPack();
3748 if (RequiresInstantiation) {
3754 SubstMapperTy =
D->getType();
3756 if (SubstMapperTy.
isNull())
3759 auto *PrevDeclInScope =
D->getPrevDeclInScope();
3760 if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) {
3761 PrevDeclInScope = cast<OMPDeclareMapperDecl>(
3765 bool IsCorrect =
true;
3771 (*
D->clauselist_begin())->getBeginLoc());
3776 cast<DeclRefExpr>(
D->getMapperVarRef())->getDecl(),
3777 cast<DeclRefExpr>(MapperVarRef.
get())->getDecl());
3778 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(Owner);
3783 auto *OldC = cast<OMPMapClause>(
C);
3785 for (
Expr *OE : OldC->varlist()) {
3791 NewVars.push_back(NE);
3799 SS.
Adopt(NewQualifierLoc);
3805 OldC->getIteratorModifier(), OldC->getMapTypeModifiers(),
3806 OldC->getMapTypeModifiersLoc(), SS, NewNameInfo, OldC->getMapType(),
3807 OldC->isImplicitMapType(), OldC->getMapLoc(), OldC->getColonLoc(),
3809 Clauses.push_back(NewC);
3815 nullptr, Owner,
D->getDeclName(), SubstMapperTy,
D->
getLocation(),
3816 VN,
D->
getAccess(), MapperVarRef.
get(), Clauses, PrevDeclInScope);
3817 Decl *NewDMD = DG.
get().getSingleDecl();
3822Decl *TemplateDeclInstantiator::VisitOMPCapturedExprDecl(
3824 llvm_unreachable(
"Should not be met in templates");
3834 if (Inst && !
D->getDescribedFunctionTemplate())
3844 llvm_unreachable(
"There are only CXXRecordDecls in C++");
3848TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
3855 "can only instantiate an explicit specialization "
3856 "for a member class template");
3863 if (!InstClassTemplate)
3870 D->getTemplateArgsAsWritten()) {
3871 InstTemplateArgs.
setLAngleLoc(TemplateArgsInfo->getLAngleLoc());
3872 InstTemplateArgs.
setRAngleLoc(TemplateArgsInfo->getRAngleLoc());
3875 TemplateArgs, InstTemplateArgs))
3883 InstTemplateArgs,
false,
3884 SugaredConverted, CanonicalConverted,
3890 void *InsertPos =
nullptr;
3899 D->getSpecializationKind(),
3919 D->isThisDeclarationADefinition()) {
3922 diag::note_previous_definition);
3930 D->
getLocation(), InstClassTemplate, CanonicalConverted, PrevDecl);
3954 if (
D->isThisDeclarationADefinition() &&
3968 assert(VarTemplate &&
3969 "A template specialization without specialized template?");
3974 if (!InstVarTemplate)
3979 D->getTemplateArgsAsWritten()) {
3980 VarTemplateArgsInfo.
setLAngleLoc(TemplateArgsInfo->getLAngleLoc());
3981 VarTemplateArgsInfo.
setRAngleLoc(TemplateArgsInfo->getRAngleLoc());
3984 TemplateArgs, VarTemplateArgsInfo))
3991 VarTemplateArgsInfo,
false,
3992 SugaredConverted, CanonicalConverted,
3997 void *InsertPos =
nullptr;
4011 InstVarTemplate,
D, VarTemplateArgsInfo, CanonicalConverted, PrevDecl);
4022 SemaRef.
SubstType(
D->getTypeSourceInfo(), TemplateArgs,
4023 D->getTypeSpecStartLoc(),
D->getDeclName());
4028 SemaRef.
Diag(
D->
getLocation(), diag::err_variable_instantiates_to_function)
4029 <<
D->isStaticDataMember() << DI->
getType();
4036 VarTemplate, DI->
getType(), DI,
D->getStorageClass(), Converted);
4039 void *InsertPos =
nullptr;
4052 StartingScope,
false, PrevDecl);
4058 llvm_unreachable(
"@defs is not supported in Objective-C++");
4065 "cannot instantiate %0 yet");
4073 llvm_unreachable(
"Concept definitions cannot reside inside a template");
4076Decl *TemplateDeclInstantiator::VisitImplicitConceptSpecializationDecl(
4078 llvm_unreachable(
"Concept specializations cannot reside inside a template");
4088 llvm_unreachable(
"Unexpected decl");
4099 SubstD = Instantiator.Visit(D);
4114 SemaRef.
Context.
BoolTy, FPT->getParamTypes(), FPT->getExtProtoInfo());
4125 assert(OldLoc &&
"type of function is not a function type?");
4127 for (
unsigned I = 0, N = OldLoc.getNumParams(); I != N; ++I)
4128 NewLoc.
setParam(I, OldLoc.getParam(I));
4138 if (Spaceship->isInvalidDecl())
4150 if (
auto *MD = dyn_cast<CXXMethodDecl>(Spaceship)) {
4155 assert(Spaceship->getFriendObjectKind() &&
4156 "defaulted spaceship is neither a member nor a friend");
4166 cast<NamedDecl>(R), Spaceship->getBeginLoc());
4170 return cast_or_null<FunctionDecl>(R);
4184 unsigned N = L->
size();
4188 for (
auto &
P : *L) {
4190 Params.push_back(
D);
4210 bool EvaluateConstraints) {
4257 ClassTemplate, PartialSpec->
getLocation(), InstTemplateArgs,
4258 false, SugaredConverted, CanonicalConverted))
4264 CanonicalConverted))
4269 void *InsertPos =
nullptr;
4284 ClassTemplate, CanonicalConverted, CanonType,
4312 diag::err_partial_spec_redeclared)
4314 SemaRef.
Diag(PrevDecl->
getLocation(), diag::note_prev_partial_spec_here)
4326 return InstPartialSpec;
4370 VarTemplate, PartialSpec->
getLocation(), InstTemplateArgs,
4371 false, SugaredConverted, CanonicalConverted))
4377 CanonicalConverted))
4382 void *InsertPos =
nullptr;
4396 diag::err_variable_instantiates_to_function)
4433 diag::err_var_partial_spec_redeclared)
4436 diag::note_var_prev_partial_spec_here);
4447 LateAttrs, Owner, StartingScope);
4449 return InstPartialSpec;
4456 assert(OldTInfo &&
"substituting function without type source info");
4457 assert(Params.empty() &&
"parameter vector is non-empty at start");
4462 ThisContext = cast<CXXRecordDecl>(Owner);
4463 ThisTypeQuals = Method->getFunctionObjectParameterType().getQualifiers();
4467 OldTInfo, TemplateArgs,
D->getTypeSpecStartLoc(),
D->getDeclName(),
4468 ThisContext, ThisTypeQuals, EvaluateConstraints);
4474 if (NewTInfo != OldTInfo) {
4478 unsigned NewIdx = 0;
4479 for (
unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
4480 OldIdx != NumOldParams; ++OldIdx) {
4481 ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
4487 std::optional<unsigned> NumArgumentsInExpansion;
4489 NumArgumentsInExpansion =
4492 if (!NumArgumentsInExpansion) {
4496 Params.push_back(NewParam);
4497 Scope->InstantiatedLocal(OldParam, NewParam);
4500 Scope->MakeInstantiatedLocalArgPack(OldParam);
4501 for (
unsigned I = 0; I != *NumArgumentsInExpansion; ++I) {
4503 Params.push_back(NewParam);
4504 Scope->InstantiatedLocalPackArg(OldParam, NewParam);
4513 cast<FunctionProtoType>(OldProtoLoc.getType());
4514 for (
unsigned i = 0, i_end = OldProtoLoc.getNumParams(); i != i_end;
4524 cast_or_null<ParmVarDecl>(VisitParmVarDecl(OldParam));
4527 Params.push_back(Parm);
4544 TemplateArgs, ParamTypes, &Params,
4557 for (
auto *
decl : PatternDecl->
decls()) {
4558 if (!isa<VarDecl>(
decl) || isa<ParmVarDecl>(
decl))
4564 auto it = llvm::find_if(
Function->decls(), [&](
Decl *inst) {
4565 VarDecl *InstVD = dyn_cast<VarDecl>(inst);
4566 return InstVD && InstVD->isLocalVarDecl() &&
4567 InstVD->getIdentifier() == II;
4573 Scope.InstantiatedLocal(VD, *it);
4574 LSI->
addCapture(cast<VarDecl>(*it),
false,
false,
4580bool Sema::addInstantiatedParametersToScope(
4584 unsigned FParamIdx = 0;
4585 for (
unsigned I = 0, N = PatternDecl->
getNumParams(); I != N; ++I) {
4589 assert(FParamIdx < Function->getNumParams());
4607 Scope.InstantiatedLocal(PatternParam, FunctionParam);
4613 Scope.MakeInstantiatedLocalArgPack(PatternParam);
4614 std::optional<unsigned> NumArgumentsInExpansion =
4616 if (NumArgumentsInExpansion) {
4619 for (
unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
4632 Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
4664 false, std::nullopt,
4671 L->DefaultArgumentInstantiated(Param);
4693 Diag(PointOfInstantiation, diag::err_exception_spec_cycle) <<
Decl;
4705 false, std::nullopt,
4713 if (addInstantiatedParametersToScope(
Decl, Template,
Scope, TemplateArgs)) {