Lines Matching +full:d +full:- +full:tlb +full:- +full:sets

1 //===------- SemaTemplateInstantiate.cpp - C++ Template Instantiation ------===/
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===/
10 //===----------------------------------------------------------------------===/
49 //===----------------------------------------------------------------------===/
51 //===----------------------------------------------------------------------===/
76 return ChangeDecl(CurDecl->getDeclContext());
95 LambdaCallOperator->getDescribedTemplate());
96 FTD && FTD->getInstantiatedFromMemberTemplate()) {
98 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
99 } else if (LambdaCallOperator->getPrimaryTemplate()) {
103 LambdaCallOperator->getPrimaryTemplate()->getTemplatedDecl();
105 ->getInstantiatedFromMemberFunction())
131 *Next = TATD->getInstantiatedFromMemberTemplate();
139 Next = Next->getInstantiatedFromMemberTemplate();
160 return getPrimaryTemplateOfGenericLambda(LE->getCallOperator()) !=
167 PrimaryTypeAliasDecl->getTemplatedDecl()->getUnderlyingType();
178 // For a class-scope explicit specialization, there are no template arguments
180 if (VarTemplSpec->isClassScopeExplicitSpecialization())
184 if (VarTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization &&
190 assert(VarTemplSpec->getSpecializedTemplate() && "No variable template?");
192 Specialized = VarTemplSpec->getSpecializedTemplateOrPartial();
197 Partial, VarTemplSpec->getTemplateInstantiationArgs().asArray(),
199 if (Partial->isMemberSpecialization())
205 Tmpl, VarTemplSpec->getTemplateInstantiationArgs().asArray(),
207 if (Tmpl->isMemberSpecialization())
222 for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
231 Result.addOuterRetainedLevels(PartialClassTemplSpec->getTemplateDepth());
240 if (!ClassTemplSpec->isClassScopeExplicitSpecialization()) {
242 if (ClassTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization &&
249 ClassTemplSpec->getTemplateInstantiationArgs().asArray(),
254 assert(ClassTemplSpec->getSpecializedTemplate() && "No class template?");
255 if (ClassTemplSpec->getSpecializedTemplate()->isMemberSpecialization())
262 if (auto *InstFromPartialTempl = ClassTemplSpec->getSpecializedTemplateOrPartial()
264 return Response::ChangeDecl(InstFromPartialTempl->getLexicalDeclContext());
275 Function->getTemplateSpecializationKindForInstantiation() ==
280 Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
286 Function->getTemplateSpecializationArgs()) {
289 TemplateArgs->asArray(),
293 (Function->getTemplateSpecializationKind() ==
295 (Function->getFriendObjectKind() &&
296 !Function->getPrimaryTemplate()->getFriendObjectKind())))
301 assert(Function->getPrimaryTemplate() && "No function template?");
302 if (Function->getPrimaryTemplate()->isMemberSpecialization())
310 } else if (Function->getDescribedFunctionTemplate()) {
319 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
320 Function->getNonTransparentDeclContext()->isFileContext() &&
321 (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) {
322 return Response::ChangeDecl(Function->getLexicalDeclContext());
325 if (ForConstraintInstantiation && Function->getFriendObjectKind())
326 return Response::ChangeDecl(Function->getLexicalDeclContext());
332 if (!isa<ClassTemplateSpecializationDecl>(FTD->getDeclContext())) {
335 const_cast<FunctionTemplateDecl *>(FTD)->getInjectedTemplateArgs(),
338 NestedNameSpecifier *NNS = FTD->getTemplatedDecl()->getQualifier();
340 while (const Type *Ty = NNS ? NNS->getAsType() : nullptr) {
341 if (NNS->isInstantiationDependent()) {
342 if (const auto *TSTy = Ty->getAs<TemplateSpecializationType>()) {
343 ArrayRef<TemplateArgument> Arguments = TSTy->template_arguments();
344 // Prefer template arguments from the injected-class-type if possible.
356 // TSTy->template_arguments() (which are of PackExpansionType)
361 if (TSTy->isCurrentInstantiation()) {
362 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
363 if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())
364 Arguments = CTD->getInjectedTemplateArgs();
368 Specialization->getTemplateInstantiationArgs().asArray();
376 NNS = NNS->getPrefix();
380 return Response::ChangeDecl(FTD->getLexicalDeclContext());
387 if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) {
391 if (ClassTemplate->isMemberSpecialization())
395 ClassTemplate->getInjectedTemplateArgs(),
400 Rec->getMemberSpecializationInfo())
401 if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
404 bool IsFriend = Rec->getFriendObjectKind() ||
405 (Rec->getDescribedClassTemplate() &&
406 Rec->getDescribedClassTemplate()->getFriendObjectKind());
408 Rec->getNonTransparentDeclContext()->isFileContext()) {
409 return Response::ChangeDecl(Rec->getLexicalDeclContext());
414 if (Rec->isLambda()) {
415 if (const Decl *LCD = Rec->getLambdaContextDecl())
422 if (isLambdaEnclosedByTypeAliasDecl(Rec->getLambdaCallOperator(),
440 return Response::ChangeDecl(TypeAlias.Template->getDeclContext());
453 CSD->getTemplateArguments(),
495 while (!CurDecl->isFileContextDecl()) {
520 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
610 .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
823 --NonInstantiationEntries;
854 {Active.Entity->getCanonicalDecl(), Active.Kind});
872 Arg->IgnoreParens()->printPretty(OS, nullptr,
883 if ((SemaRef.CodeSynthesisContexts.size() -
903 SkipEnd = CodeSynthesisContexts.size() - Limit / 2;
917 Diags.Report(Active->PointOfInstantiation,
919 << unsigned(CodeSynthesisContexts.size() - Limit);
924 switch (Active->Kind) {
926 Decl *D = Active->Entity;
927 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
931 Diags.Report(Active->PointOfInstantiation, DiagID)
932 << Record << Active->InstantiationRange;
933 } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
935 if (Function->getPrimaryTemplate())
939 Diags.Report(Active->PointOfInstantiation, DiagID)
941 << Active->InstantiationRange;
942 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
943 Diags.Report(Active->PointOfInstantiation,
944 VD->isStaticDataMember()?
948 << Active->InstantiationRange;
949 } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
950 Diags.Report(Active->PointOfInstantiation,
953 << Active->InstantiationRange;
954 } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
955 Diags.Report(Active->PointOfInstantiation,
957 << FD << Active->InstantiationRange;
958 } else if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(D)) {
959 Diags.Report(Active->PointOfInstantiation,
961 << CTD << Active->InstantiationRange;
967 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
970 Template->printName(OS, getPrintingPolicy());
971 printTemplateArgumentList(OS, Active->template_arguments(),
973 Diags.Report(Active->PointOfInstantiation,
976 << Active->InstantiationRange;
981 FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity);
982 Diags.Report(Active->PointOfInstantiation,
985 << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
986 Active->TemplateArgs,
987 Active->NumTemplateArgs)
988 << Active->InstantiationRange;
994 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
995 Diags.Report(Active->PointOfInstantiation,
998 << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
999 Active->TemplateArgs,
1000 Active->NumTemplateArgs)
1001 << Active->InstantiationRange;
1003 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
1004 isa<VarTemplateSpecializationDecl>(Active->Entity);
1007 if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1009 Params = D->getTemplateParameters();
1010 } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1011 Active->Entity)) {
1012 Params = D->getTemplateParameters();
1013 } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1014 Active->Entity)) {
1015 Params = D->getTemplateParameters();
1020 Diags.Report(Active->PointOfInstantiation,
1022 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
1023 << getTemplateArgumentBindingsText(Params, Active->TemplateArgs,
1024 Active->NumTemplateArgs)
1025 << Active->InstantiationRange;
1031 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
1032 FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
1036 FD->printName(OS, getPrintingPolicy());
1037 printTemplateArgumentList(OS, Active->template_arguments(),
1039 Diags.Report(Active->PointOfInstantiation,
1042 << Active->InstantiationRange;
1047 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
1049 if (!Parm->getName().empty())
1050 Name = std::string(" '") + Parm->getName().str() + "'";
1053 if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1054 TemplateParams = Template->getTemplateParameters();
1057 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1058 ->getTemplateParameters();
1059 Diags.Report(Active->PointOfInstantiation,
1064 Active->TemplateArgs,
1065 Active->NumTemplateArgs)
1066 << Active->InstantiationRange;
1072 if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1073 TemplateParams = Template->getTemplateParameters();
1076 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1077 ->getTemplateParameters();
1079 Diags.Report(Active->PointOfInstantiation,
1082 Active->TemplateArgs,
1083 Active->NumTemplateArgs)
1084 << Active->InstantiationRange;
1089 Diags.Report(Active->PointOfInstantiation,
1091 << cast<FunctionDecl>(Active->Entity);
1095 Diags.Report(Active->PointOfInstantiation,
1097 << cast<FunctionDecl>(Active->Entity)
1098 << Active->InstantiationRange;
1102 Diags.Report(Active->PointOfInstantiation,
1104 << Active->InstantiationRange;
1107 Diags.Report(Active->PointOfInstantiation,
1109 << Active->InstantiationRange;
1113 Diags.Report(Active->PointOfInstantiation,
1115 << Active->InstantiationRange;
1119 Diags.Report(Active->PointOfInstantiation,
1121 << cast<CXXRecordDecl>(Active->Entity)
1122 << llvm::to_underlying(Active->SpecialMember);
1126 Diags.Report(Active->Entity->getLocation(),
1133 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1138 Diags.Report(Active->PointOfInstantiation,
1140 << MD->isExplicitlyDefaulted()
1142 << Context.getTagDeclType(MD->getParent());
1144 QualType RecordType = FD->getParamDecl(0)
1145 ->getType()
1148 Diags.Report(Active->PointOfInstantiation,
1156 Diags.Report(Active->Entity->getLocation(),
1161 Diags.Report(Active->PointOfInstantiation,
1163 << cast<BindingDecl>(Active->Entity);
1167 Diags.Report(Active->PointOfInstantiation,
1169 << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11;
1173 Diags.Report(Active->PointOfInstantiation,
1176 *this, llvm::ArrayRef(Active->CallArgs, Active->NumCallArgs));
1183 Diags.Report(Active->PointOfInstantiation,
1188 if (!Active->Entity) {
1189 Diags.Report(Active->PointOfInstantiation,
1191 << Active->InstantiationRange;
1194 if (isa<ConceptDecl>(Active->Entity))
1196 else if (isa<TemplateDecl>(Active->Entity))
1198 else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
1200 else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
1203 assert(isa<FunctionDecl>(Active->Entity));
1208 cast<NamedDecl>(Active->Entity)->printName(OS, getPrintingPolicy());
1209 if (!isa<FunctionDecl>(Active->Entity)) {
1210 printTemplateArgumentList(OS, Active->template_arguments(),
1213 Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str()
1214 << Active->InstantiationRange;
1218 Diags.Report(Active->PointOfInstantiation,
1220 << Active->InstantiationRange;
1223 Diags.Report(Active->PointOfInstantiation,
1225 << cast<NamedDecl>(Active->Entity)->getName()
1226 << Active->InstantiationRange;
1229 Diags.Report(Active->PointOfInstantiation,
1231 << Active->InstantiationRange;
1234 Diags.Report(Active->PointOfInstantiation,
1238 Diags.Report(Active->PointOfInstantiation,
1240 << cast<TypeAliasTemplateDecl>(Active->Entity)
1241 << Active->InstantiationRange;
1257 switch (Active->Kind) {
1261 if (isa<TypeAliasTemplateDecl>(Active->Entity))
1275 // A lambda-expression appearing in a function type or a template
1278 // CWG2672: A lambda-expression body is never in the immediate context.
1292 // We're either substituting explicitly-specified template arguments,
1300 assert(Active->DeductionInfo && "Missing deduction info pointer");
1301 return Active->DeductionInfo;
1325 // non-instantiation SFINAE context, then SFINAE applies.
1326 if (Active->SavedInNonInstantiationSFINAEContext)
1333 //===----------------------------------------------------------------------===/
1335 //===----------------------------------------------------------------------===/
1373 /// Sets the "base" location and entity when that
1376 this->Loc = Loc;
1377 this->Entity = Entity;
1386 if (Index == -1)
1388 return Pack.pack_size() - 1 - Index;
1405 SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack);
1411 = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){
1413 = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
1430 = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){
1432 = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
1441 Decl *TransformDecl(SourceLocation Loc, Decl *D);
1448 if (Old->isParameterPack()) {
1449 SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old);
1451 SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg(
1466 if (auto *NewTD = NewMD->getDescribedFunctionTemplate())
1467 NewTD->setInstantiatedFromMemberTemplate(
1468 OldMD->getDescribedFunctionTemplate());
1470 NewMD->setInstantiationOfMemberFunction(OldMD,
1474 SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New);
1479 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1485 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1489 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1504 /// Rebuild the Objective-C exception declaration and register the
1537 NonTypeTemplateParmDecl *D);
1546 /// Transform a reference to a function or init-capture parameter pack.
1554 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1557 return inherited::TransformFunctionProtoType(TLB, TL);
1560 QualType TransformInjectedClassNameType(TypeLocBuilder &TLB,
1562 auto Type = inherited::TransformInjectedClassNameType(TLB, TL);
1570 if (auto *ICT = TL.getType()->getAs<InjectedClassNameType>()) {
1572 inherited::TransformType(ICT->getInjectedSpecializationType());
1573 TLB.pushTrivial(SemaRef.Context, Type, TL.getNameLoc());
1579 // Override the default version to handle a rewrite-template-arg-pack case
1609 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1623 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1628 TypeLocBuilder &TLB, bool SuppressObjCLifetime, bool Final,
1632 /// Transforms an already-substituted template type parameter pack
1637 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1647 LSI->CallOperator, TypeAlias.PrimaryTypeAliasDecl)) {
1648 unsigned TypeAliasDeclDepth = TypeAlias.Template->getTemplateDepth();
1666 CXXMethodDecl *MD = Result.getAs<LambdaExpr>()->getCallOperator();
1667 for (ParmVarDecl *PVD : MD->parameters()) {
1669 if (!PVD->hasDefaultArg())
1671 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1673 SourceLocation EqualLoc = UninstExpr->getBeginLoc();
1679 UninstExpr->getBeginLoc(), UninstExpr->getEndLoc(),
1680 { UninstExpr }, UninstExpr->getType());
1682 PVD->setDefaultArg(ErrorResult.get());
1714 if (E->getBody()->isDependentContext()) {
1718 SemaRef.PerformDependentDiagnostics(E->getBody(), TemplateArgs);
1721 TransReq.getAs<RequiresExpr>()->setSatisfied(false);
1742 if (!TransReq->isDependent() && !TransReq->isSatisfied())
1746 // determines the result of the requires-expression is
1758 if (!OrigTPL || !OrigTPL->size()) return OrigTPL;
1760 DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext();
1793 if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
1810 Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1811 if (!D)
1814 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1815 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1816 // If the corresponding template argument is NULL or non-existent, it's
1817 // because we are performing instantiation from explicitly-specified
1820 if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1821 TTP->getPosition()))
1822 return D;
1824 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1826 if (TTP->isParameterPack()) {
1842 return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs);
1845 Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
1846 Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs);
1850 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1865 TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
1867 // If the first part of the nested-name-specifier was a template type
1869 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
1873 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1875 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
1877 if (TTP->isParameterPack()) {
1881 if (getSema().ArgumentPackSubstitutionIndex == -1)
1889 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1891 if (const TagType *Tag = T->getAs<TagType>())
1892 return Tag->getDecl();
1900 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1912 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1921 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1930 if (const TagType *TT = T->getAs<TagType>()) {
1931 TagDecl* TD = TT->getDecl();
1935 IdentifierInfo *Id = TD->getIdentifier();
1947 TD->getKindName());
1948 SemaRef.Diag(TD->getLocation(), diag::note_previous_use);
1962 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1963 // If the corresponding template argument is NULL or non-existent, it's
1964 // because we are performing instantiation from explicitly-specified
1967 if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1968 TTP->getPosition()))
1971 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1977 assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1979 Arg = Arg.pack_begin()->getPackExpansionPattern();
1987 TemplateArgs.getAssociatedDecl(TTP->getDepth());
1989 if (TTP->isParameterPack()) {
1993 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1998 Arg, AssociatedDecl, TTP->getIndex(), Final);
2011 Template, AssociatedDecl, TTP->getIndex(), PackIndex);
2017 if (getSema().ArgumentPackSubstitutionIndex == -1)
2020 TemplateArgument Pack = SubstPack->getArgumentPack();
2023 if (SubstPack->getFinal())
2026 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2037 if (!E->isTypeDependent())
2040 return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind());
2046 // If the corresponding template argument is NULL or non-existent, it's
2047 // because we are performing instantiation from explicitly-specified
2050 if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(),
2051 NTTP->getPosition()))
2054 TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition());
2060 assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
2062 Arg = Arg.pack_begin()->getPackExpansionPattern();
2071 auto [AssociatedDecl, _] = TemplateArgs.getAssociatedDecl(NTTP->getDepth());
2073 if (NTTP->isParameterPack()) {
2077 if (getSema().ArgumentPackSubstitutionIndex == -1) {
2081 QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs,
2082 E->getLocation(),
2083 NTTP->getDeclName());
2088 if (TargetType->isRecordType())
2092 ExprType, TargetType->isReferenceType() ? VK_LValue : VK_PRValue,
2093 E->getLocation(), Arg, AssociatedDecl, NTTP->getPosition());
2099 return transformNonTypeTemplateParmRef(AssociatedDecl, NTTP, E->getLocation(),
2105 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2109 Res = getSema().BuildCXXAssumeExpr(Res.get(), AA->getAttrName(),
2110 AA->getRange());
2115 AA->getRange());
2120 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
2122 if (TransformedExpr == LH->getValue())
2126 if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation(),
2127 LH->getSemanticSpelling() ==
2131 LoopHintAttr::OptionType Option = LH->getOption();
2132 LoopHintAttr::LoopHintState State = LH->getState();
2135 TransformedExpr->EvaluateKnownConstInt(getSema().getASTContext());
2143 // non-type template parameter.
2164 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2178 if (parm->isExpandedParameterPack())
2179 T = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex);
2181 T = parm->getType();
2182 if (parm->isParameterPack() && isa<PackExpansionType>(T))
2183 T = cast<PackExpansionType>(T)->getPattern();
2184 return SemaRef.SubstType(T, TemplateArgs, loc, parm->getDeclName());
2195 if (argExpr->isLValue()) {
2196 if (argExpr->getType()->isRecordType()) {
2201 refParam = paramType->isReferenceType();
2221 assert(!paramType->isDependentType() && "param type still dependent");
2223 refParam = paramType->isReferenceType();
2227 refParam = paramType->isReferenceType();
2229 SemaRef.Context.hasSameType(result.get()->getType(),
2239 resultExpr->getType(), resultExpr->getValueKind(), loc, resultExpr,
2240 AssociatedDecl, parm->getIndex(), PackIndex, refParam);
2246 if (getSema().ArgumentPackSubstitutionIndex == -1) {
2251 TemplateArgument Pack = E->getArgumentPack();
2255 E->getAssociatedDecl(), E->getParameterPack(),
2256 E->getParameterPackLocation(), Arg, getPackIndex(Pack));
2262 ExprResult SubstReplacement = E->getReplacement();
2264 SubstReplacement = TransformExpr(E->getReplacement());
2267 QualType SubstType = TransformType(E->getParameterType(getSema().Context));
2292 .CheckTemplateArgument(E->getParameter(), SubstType,
2297 return transformNonTypeTemplateParmRef(E->getAssociatedDecl(),
2298 E->getParameter(), E->getExprLoc(),
2299 SugaredConverted, E->getPackIndex());
2304 DeclarationNameInfo NameInfo(PD->getDeclName(), Loc);
2310 if (getSema().ArgumentPackSubstitutionIndex != -1) {
2312 VarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex);
2313 VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D));
2316 return RebuildVarDeclRefExpr(VD, E->getExprLoc());
2319 QualType T = TransformType(E->getType());
2326 Vars.reserve(E->getNumExpansions());
2327 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
2329 VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I));
2330 if (!D)
2332 Vars.push_back(D);
2336 FunctionParmPackExpr::Create(getSema().Context, T, E->getParameterPack(),
2337 E->getParameterPackLocation(), Vars);
2347 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2351 if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
2354 if (getSema().ArgumentPackSubstitutionIndex == -1) {
2355 QualType T = TransformType(E->getType());
2359 E->getExprLoc(), *Pack);
2366 TransformedDecl = Found->get<Decl*>();
2370 return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc());
2375 NamedDecl *D = E->getDecl();
2377 // Handle references to non-type template parameters and non-type template
2379 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
2380 if (NTTP->getDepth() < TemplateArgs.getNumLevels())
2383 // We have a non-type template parameter that isn't fully substituted;
2388 if (VarDecl *PD = dyn_cast<VarDecl>(D))
2389 if (PD->isParameterPack())
2397 assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->
2401 E->getUsedLocation(), cast<FunctionDecl>(E->getParam()->getDeclContext()),
2402 E->getParam());
2406 QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
2414 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2429 TypeLocBuilder &TLB, bool SuppressObjCLifetime, bool Final,
2445 TLB.pushTrivial(SemaRef.Context, Replacement, NameLoc);
2452 TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
2458 TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2462 if (T->getDepth() < TemplateArgs.getNumLevels()) {
2467 // because we are performing instantiation from explicitly-specified
2470 if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) {
2472 = TLB.push<TemplateTypeParmTypeLoc>(TL.getType());
2477 TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
2483 assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
2485 Arg = Arg.pack_begin()->getPackExpansionPattern();
2490 TLB.pushTrivial(SemaRef.Context, NewT, TL.getNameLoc());
2495 TemplateArgs.getAssociatedDecl(T->getDepth());
2497 if (T->isParameterPack()) {
2501 if (getSema().ArgumentPackSubstitutionIndex == -1) {
2506 AssociatedDecl, T->getIndex(), Final, Arg);
2508 = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result);
2521 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2522 AssociatedDecl, T->getIndex(),
2531 if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl())
2535 T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(),
2536 T->isParameterPack(), NewTTPDecl);
2537 TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result);
2543 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
2547 Decl *NewReplaced = TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
2549 if (getSema().ArgumentPackSubstitutionIndex == -1) {
2552 if (NewReplaced != T->getAssociatedDecl())
2554 NewReplaced, T->getIndex(), T->getFinal(), T->getArgumentPack());
2556 TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result);
2561 TemplateArgument Pack = T->getArgumentPack();
2564 TLB, SuppressObjCLifetime, T->getFinal(), NewReplaced, T->getIndex(),
2626 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->getLParenLoc(),
2627 TransParams, RE->getRParenLoc(),
2636 if (!Req->isDependent() && !AlwaysRebuild())
2638 if (Req->isSubstitutionFailure()) {
2641 Req->getSubstitutionDiagnostic());
2646 TemplateDeductionInfo Info(Req->getType()->getTypeLoc().getBeginLoc());
2648 Req->getType()->getTypeLoc().getBeginLoc(), Req, Info,
2649 Req->getType()->getTypeLoc().getSourceRange());
2652 TypeSourceInfo *TransType = TransformType(Req->getType());
2656 Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy());
2663 if (!Req->isDependent() && !AlwaysRebuild())
2670 if (Req->isExprSubstitutionFailure())
2671 TransExpr = Req->getExprSubstitutionDiagnostic();
2673 Expr *E = Req->getExpr();
2674 TemplateDeductionInfo Info(E->getBeginLoc());
2675 Sema::InstantiatingTemplate ExprInst(SemaRef, E->getBeginLoc(), Req, Info,
2676 E->getSourceRange());
2681 TransExprRes.get()->hasPlaceholderType())
2685 E->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
2692 const auto &RetReq = Req->getReturnTypeRequirement();
2700 TemplateDeductionInfo Info(OrigTPL->getTemplateLoc());
2701 Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(),
2702 Req, Info, OrigTPL->getSourceRange());
2709 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2710 ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
2719 return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(),
2723 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
2729 if (!Req->isDependent() && !AlwaysRebuild())
2731 if (Req->hasInvalidConstraint()) {
2733 return RebuildNestedRequirement(Req->getInvalidConstraintEntity(),
2734 Req->getConstraintSatisfaction());
2738 Req->getConstraintExpr()->getBeginLoc(), Req,
2740 Req->getConstraintExpr()->getSourceRange());
2742 ExprResult TransConstraint = TransformExpr(Req->getConstraintExpr());
2745 if (TransConstraint.get()->isInstantiationDependent())
2755 TemplateDeductionInfo Info(Req->getConstraintExpr()->getBeginLoc());
2761 Req->getConstraintExpr()->getBeginLoc(), Req, Info,
2762 Req->getConstraintExpr()->getSourceRange());
2767 nullptr, {Req->getConstraintExpr()}, Result, TemplateArgs,
2768 Req->getConstraintExpr()->getSourceRange(), Satisfaction) &&
2776 TransConstraint.get()->isInstantiationDependent())
2782 Req->getConstraintExpr()->printPretty(OS, nullptr,
2800 if (!T->getType()->isInstantiationDependentType() &&
2801 !T->getType()->isVariablyModifiedType())
2820 if (!TL.getType()->isInstantiationDependentType() &&
2821 !TL.getType()->isVariablyModifiedType()) {
2824 TypeLocBuilder TLB;
2825 TLB.pushFullCopy(TL);
2826 return TLB.getTypeSourceInfo(Context, TL.getType());
2830 TypeLocBuilder TLB;
2831 TLB.reserve(TL.getFullDataSize());
2832 QualType Result = Instantiator.TransformType(TLB, TL);
2836 return TLB.getTypeSourceInfo(Context, Result);
2847 // If T is not a dependent type or a variably-modified type, there
2849 if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
2857 if (T->getType()->isInstantiationDependentType() ||
2858 T->getType()->isVariablyModifiedType())
2861 TypeLoc TL = T->getTypeLoc().IgnoreParens();
2895 TypeLocBuilder TLB;
2897 TypeLoc TL = T->getTypeLoc();
2898 TLB.reserve(TL.getFullDataSize());
2910 TLB, Proto, ThisContext, ThisTypeQuals,
2914 Result = Instantiator.TransformType(TLB, TL);
2918 if (Result.isNull() || !Result->isFunctionType())
2921 return TLB.getTypeSourceInfo(Context, Result);
2937 Proto->getExtProtoInfo().ExceptionSpec;
2940 if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(),
2964 if (!T->getDecl() || !T->getDecl()->isImplicit())
2966 return T->getDecl();
2973 return Visit(T->getNamedType());
2977 return Visit(T->getPointeeType());
2981 return Visit(T->getPointeeType());
2985 return Visit(T->getPointeeTypeAsWritten());
2989 return Visit(T->getPointeeType());
2993 return Visit(T->getElementType());
2998 return Visit(T->getElementType());
3002 return Visit(T->getElementType());
3010 return Visit(T->getReturnType());
3014 return Visit(T->getInnerType());
3018 return Visit(T->getModifiedType());
3022 return Visit(T->getUnderlyingType());
3026 return Visit(T->getOriginalType());
3030 return Visit(T->getPattern());
3041 TC->getTemplateArgsAsWritten();
3044 Inst->setTypeConstraint(TC->getConceptReference(),
3045 TC->getImmediatelyDeclaredConstraint());
3052 InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
3053 InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
3054 if (SubstTemplateArguments(TemplArgInfo->arguments(), TemplateArgs,
3059 TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
3060 TC->getNamedConcept(),
3061 /*FoundDecl=*/TC->getConceptReference()->getFoundDecl(), &InstArgs, Inst,
3062 Inst->isParameterPack()
3063 ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
3064 ->getEllipsisLoc()
3072 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3075 TypeLoc OldTL = OldDI->getTypeLoc();
3081 OldParm->getLocation(), OldParm->getDeclName());
3085 if (NewDI->getType()->containsUnexpandedParameterPack()) {
3096 Diag(OldParm->getLocation(),
3098 << NewDI->getType();
3102 NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(),
3103 OldParm->getDeclName());
3109 if (NewDI->getType()->isVoidType()) {
3110 Diag(OldParm->getLocation(), diag::err_param_with_void_type);
3121 GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
3122 if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
3124 FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs));
3128 if (Inst && !Inst->getTypeConstraint()) {
3136 OldParm->getInnerLocStart(),
3137 OldParm->getLocation(),
3138 OldParm->getIdentifier(),
3139 NewDI->getType(), NewDI,
3140 OldParm->getStorageClass());
3145 if (OldParm->hasUninstantiatedDefaultArg()) {
3146 Expr *Arg = OldParm->getUninstantiatedDefaultArg();
3147 NewParm->setUninstantiatedDefaultArg(Arg);
3148 } else if (OldParm->hasUnparsedDefaultArg()) {
3149 NewParm->setUnparsedDefaultArg();
3151 } else if (Expr *Arg = OldParm->getDefaultArg()) {
3162 NewParm->setUninstantiatedDefaultArg(Arg);
3165 NewParm->setExplicitObjectParameterLoc(
3166 OldParm->getExplicitObjectParamThisLoc());
3167 NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg());
3169 if (OldParm->isParameterPack() && !NewParm->isParameterPack()) {
3171 CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm);
3173 // Introduce an Old -> New mapping
3174 CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm);
3179 NewParm->setDeclContext(CurContext);
3181 NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3182 OldParm->getFunctionScopeIndex() + indexAdjustment);
3211 FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
3212 Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
3221 Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD;
3222 Param->setInvalidDecl();
3243 FunctionDecl *PatternFD = FD->getTemplateInstantiationPattern(
3247 const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
3248 if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) {
3253 FD, FD->getDeclContext(), /*Final=*/false,
3254 CurrentTemplateArgumentList->asArray(), /*RelativeToPrimary=*/true);
3271 Param->getLocation(),
3272 /*FIXME:EqualLoc*/ PatternExpr->getBeginLoc());
3281 ActOnFinishFullExpr(Result.getAs<Expr>(), Param->getOuterLocStart(),
3285 SourceLocation EqualLoc = PatternExpr->getBeginLoc();
3292 Param->setDefaultArg(Result.getAs<Expr>());
3303 for (const auto &Base : Pattern->bases()) {
3304 if (!Base.getType()->isDependentType()) {
3305 if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) {
3306 if (RD->isInvalidDecl())
3307 Instantiation->setInvalidDecl();
3319 collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(),
3365 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
3418 = cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
3420 Instantiation->getInstantiatedFromMemberClass(),
3427 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
3430 auto Loc = SourceMgr.getExpansionLoc(Instantiation->getLocation());
3441 = Instantiation->getMemberSpecializationInfo()) {
3442 MSInfo->setTemplateSpecializationKind(TSK);
3443 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3446 Spec->setTemplateSpecializationKind(TSK);
3447 Spec->setPointOfInstantiation(PointOfInstantiation);
3466 bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
3479 Instantiation->startDefinition();
3483 Instantiation->setVisibleDespiteOwningModule();
3485 // FIXME: This loses the as-written tag kind for an explicit instantiation.
3486 Instantiation->setTagKind(Pattern->getTagKind());
3490 Instantiation->setInvalidDecl();
3500 for (auto *Member : Pattern->decls()) {
3510 if (Member->getDeclContext() != Pattern)
3513 // BlockDecls can appear in a default-member-initializer. They must be the
3518 (isa<CXXRecordDecl>(Member) && cast<CXXRecordDecl>(Member)->isLambda()))
3521 if (Member->isInvalidDecl()) {
3522 Instantiation->setInvalidDecl();
3535 if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
3536 Enum->isCompleteDefinition()) {
3537 MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
3539 MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
3540 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3543 if (SA->isFailed()) {
3546 Instantiation->setInvalidDecl();
3550 if (MD->isConstexpr() && !MD->getFriendObjectKind() &&
3551 (MD->isVirtualAsWritten() || Instantiation->getNumBases()))
3555 if (NewMember->isInvalidDecl())
3556 Instantiation->setInvalidDecl();
3566 ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
3581 CurrentInstantiationScope = I->Scope;
3583 // Allow 'this' within late-parsed attributes.
3584 auto *ND = cast<NamedDecl>(I->NewDecl);
3585 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3587 ND->isCXXInstanceMember());
3590 instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);
3592 I->NewDecl->addAttr(NewAttr);
3593 LocalInstantiationScope::deleteScopes(I->Scope,
3604 Instantiation->setLocation(Pattern->getLocation());
3605 Instantiation->setLocStart(Pattern->getInnerLocStart());
3606 Instantiation->setBraceRange(Pattern->getBraceRange());
3609 if (!Instantiation->isInvalidDecl()) {
3611 if (Pattern->isDependentContext())
3614 // Instantiate any out-of-line class template partial
3621 P->first, P->second)) {
3622 Instantiation->setInvalidDecl();
3627 // Instantiate any out-of-line variable template partial
3634 P->first, P->second)) {
3635 Instantiation->setInvalidDecl();
3644 if (!Instantiation->isInvalidDecl()) {
3658 return Instantiation->isInvalidDecl();
3665 EnumDecl *PatternDef = Pattern->getDefinition();
3667 Instantiation->getInstantiatedFromMemberEnum(),
3674 = Instantiation->getMemberSpecializationInfo()) {
3675 MSInfo->setTemplateSpecializationKind(TSK);
3676 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3689 Instantiation->setVisibleDespiteOwningModule();
3708 return Instantiation->isInvalidDecl();
3715 if (!Pattern->hasInClassInitializer())
3718 assert(Instantiation->getInClassInitStyle() ==
3719 Pattern->getInClassInitStyle() &&
3724 Expr *OldInit = Pattern->getInClassInitializer();
3726 RecordDecl *PatternRD = Pattern->getParent();
3727 RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext();
3731 Diag(Pattern->getEndLoc(),
3733 Instantiation->setInvalidDecl();
3751 ContextRAII SavedContext(*this, Instantiation->getParent());
3761 CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers());
3766 assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class");
3768 Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init);
3771 L->DefaultMemberInitializerInstantiated(Instantiation);
3773 // Return true if the in-class initializer is still missing.
3774 return !Instantiation->getInClassInitializer();
3779 /// a given template-id.
3788 if (ClassTemplateSpec->getTemplateSpecializationKind() ==
3793 ClassTemplateSpec->getSpecializedTemplate()
3794 ->getPartialSpecializations(PartialSpecs);
3798 ClassTemplateSpec->getTemplateArgs().asArray(),
3822 Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
3825 ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
3838 Template->getPartialSpecializations(PartialSpecs);
3844 Partial, ClassTemplateSpec->getTemplateArgs().asArray(), Info);
3846 // Store the failed-deduction information for use in diagnostics, later.
3847 // TODO: Actually use the failed-deduction info?
3866 // -- If exactly one matching specialization is found, the
3870 // -- If more than one matching specialization is found, the
3876 // ambiguous and the program is ill-formed.
3881 P->Partial, Best->Partial, PointOfInstantiation) ==
3882 P->Partial)
3893 P->Partial, Best->Partial,
3894 PointOfInstantiation) != Best->Partial) {
3903 ClassTemplateSpec->setInvalidDecl();
3912 S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
3914 P->Partial->getTemplateParameters(), *P->Args);
3920 ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args);
3922 // -- If no matches are found, the instantiation is generated
3928 Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
3932 while (PartialSpec->getInstantiatedFromMember()) {
3935 if (PartialSpec->isMemberSpecialization())
3938 PartialSpec = PartialSpec->getInstantiatedFromMember();
3942 ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
3943 while (Template->getInstantiatedFromMemberTemplate()) {
3946 if (Template->isMemberSpecialization())
3949 Template = Template->getInstantiatedFromMemberTemplate();
3951 Pattern = Template->getTemplatedDecl();
3963 ClassTemplateSpec->getCanonicalDecl());
3964 if (ClassTemplateSpec->isInvalidDecl())
3989 (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&
3991 for (auto *D : Instantiation->decls()) {
3993 if (auto *Function = dyn_cast<FunctionDecl>(D)) {
3995 Function->getInstantiatedFromMemberFunction()) {
3997 if (Function->isIneligibleOrNotSelected())
4000 if (Function->getTrailingRequiresClause()) {
4008 if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4012 Function->getMemberSpecializationInfo();
4014 if (MSInfo->getTemplateSpecializationKind()
4020 MSInfo->getTemplateSpecializationKind(),
4021 MSInfo->getPointOfInstantiation(),
4032 if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined())
4035 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4037 if (Function->isDefined()) {
4048 } else if (auto *Var = dyn_cast<VarDecl>(D)) {
4052 if (Var->isStaticDataMember()) {
4053 if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4056 MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo();
4058 if (MSInfo->getTemplateSpecializationKind()
4064 MSInfo->getTemplateSpecializationKind(),
4065 MSInfo->getPointOfInstantiation(),
4077 if (!Var->getInstantiatedFromStaticDataMember()->getDefinition())
4080 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4083 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4086 } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) {
4087 if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4090 // Always skip the injected-class-name, along with any
4094 // the corresponding lambda-expression.
4095 if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
4096 Record->isLambda())
4099 MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();
4102 if (MSInfo->getTemplateSpecializationKind()
4119 MSInfo->getTemplateSpecializationKind(),
4120 MSInfo->getPointOfInstantiation(),
4125 CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
4126 assert(Pattern && "Missing instantiated-from-template information");
4128 if (!Record->getDefinition()) {
4129 if (!Pattern->getDefinition()) {
4137 MSInfo->setTemplateSpecializationKind(TSK);
4138 MSInfo->setPointOfInstantiation(PointOfInstantiation);
4149 Record->getTemplateSpecializationKind() ==
4151 Record->setTemplateSpecializationKind(TSK);
4156 Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
4160 } else if (auto *Enum = dyn_cast<EnumDecl>(D)) {
4161 MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo();
4164 if (MSInfo->getTemplateSpecializationKind()
4170 MSInfo->getTemplateSpecializationKind(),
4171 MSInfo->getPointOfInstantiation(), SuppressNew) ||
4175 if (Enum->getDefinition())
4178 EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
4179 assert(Pattern && "Missing instantiated-from-template information");
4182 if (!Pattern->getDefinition())
4187 MSInfo->setTemplateSpecializationKind(TSK);
4188 MSInfo->setPointOfInstantiation(PointOfInstantiation);
4190 } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
4191 // No need to instantiate in-class initializers during explicit
4193 if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
4195 Instantiation->getTemplateInstantiationPattern();
4197 ClassPattern->lookup(Field->getDeclName());
4335 static const Decl *getCanonicalParmVarDecl(const Decl *D) {
4340 if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4341 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4342 unsigned i = PV->getFunctionScopeIndex();
4345 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4346 return FD->getCanonicalDecl()->getParamDecl(i);
4349 return D;
4354 LocalInstantiationScope::findInstantiationOf(const Decl *D) {
4355 D = getCanonicalParmVarDecl(D);
4357 Current = Current->Outer) {
4360 const Decl *CheckD = D;
4362 LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
4363 if (Found != Current->LocalDecls.end())
4364 return &Found->second;
4369 CheckD = Tag->getPreviousDecl();
4375 if (!Current->CombineWithOuterScope)
4381 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
4382 isa<TemplateTemplateParmDecl>(D))
4386 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
4387 if (RD->isLocalClass())
4392 if (isa<EnumDecl>(D))
4397 if (isa<TypedefNameDecl>(D) &&
4398 isa<CXXDeductionGuideDecl>(D->getDeclContext()))
4404 assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope");
4408 void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) {
4409 D = getCanonicalParmVarDecl(D);
4410 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4415 while (Current->CombineWithOuterScope && Current->Outer) {
4416 Current = Current->Outer;
4417 assert(!Current->LocalDecls.contains(D) &&
4423 Pack->push_back(cast<VarDecl>(Inst));
4429 void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D,
4431 D = getCanonicalParmVarDecl(D);
4432 DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
4433 Pack->push_back(Inst);
4436 void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) {
4440 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4441 assert(!Current->LocalDecls.contains(D) &&
4445 D = getCanonicalParmVarDecl(D);
4446 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4452 bool LocalInstantiationScope::isLocalPackExpansion(const Decl *D) {
4454 if (llvm::is_contained(*Pack, D))
4463 "Already have a partially-substituted pack");
4466 "Wrong number of arguments in partially-substituted pack");
4481 Current = Current->Outer) {
4482 if (Current->PartiallySubstitutedPack) {
4484 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4486 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4488 return Current->PartiallySubstitutedPack;
4491 if (!Current->CombineWithOuterScope)