38#include "llvm/ADT/SmallBitVector.h"
39#include "llvm/ADT/SmallString.h"
40#include "llvm/ADT/StringExtras.h"
52 return SourceRange(Ps[0]->getTemplateLoc(), Ps[N-1]->getRAngleLoc());
60 for (
Scope *TempParamScope = S->getTemplateParamParent(); TempParamScope;
61 TempParamScope = TempParamScope->getParent()->getTemplateParamParent()) {
66 auto ParamsAtDepth = [&](
unsigned D) { Depth = std::max(Depth, D + 1); };
71 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(FSI)) {
72 if (!LSI->TemplateParams.empty()) {
73 ParamsAtDepth(LSI->AutoTemplateParameterDepth);
76 if (LSI->GLTemplateParameterList) {
77 ParamsAtDepth(LSI->GLTemplateParameterList->getDepth());
87 if (!Info.TemplateParams.empty()) {
88 ParamsAtDepth(Info.AutoTemplateParameterDepth);
103 bool AllowFunctionTemplates,
104 bool AllowDependent) {
107 if (isa<TemplateDecl>(D)) {
108 if (!AllowFunctionTemplates && isa<FunctionTemplateDecl>(D))
114 if (
const auto *Record = dyn_cast<CXXRecordDecl>(D)) {
126 if (Record->isInjectedClassName()) {
127 Record = cast<CXXRecordDecl>(Record->getDeclContext());
128 if (Record->getDescribedClassTemplate())
129 return Record->getDescribedClassTemplate();
131 if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(Record))
132 return Spec->getSpecializedTemplate();
141 if (AllowDependent && isa<UnresolvedUsingValueDecl>(D))
148 bool AllowFunctionTemplates,
149 bool AllowDependent) {
160 bool AllowFunctionTemplates,
162 bool AllowNonTemplateFunctions) {
166 if (AllowNonTemplateFunctions &&
167 isa<FunctionDecl>((*I)->getUnderlyingDecl()))
176 bool hasTemplateKeyword,
179 bool EnteringContext,
181 bool &MemberOfUnknownSpecialization,
182 bool Disambiguation) {
186 MemberOfUnknownSpecialization =
false;
188 switch (Name.getKind()) {
195 Name.OperatorFunctionId.Operator);
234 bool AnyFunctionTemplates =
false;
237 if (isa<FunctionTemplateDecl>(FoundTemplate))
238 AnyFunctionTemplates =
true;
241 FoundUsingShadow = dyn_cast<UsingShadowDecl>(FoundD);
249 if (!D && !AnyFunctionTemplates) {
250 R.suppressDiagnostics();
267 unsigned ResultCount = R.
end() - R.
begin();
268 if (!D && ResultCount > 1) {
279 assert(D &&
"unambiguous result is not a template name");
282 if (isa<UnresolvedUsingValueDecl>(D)) {
284 MemberOfUnknownSpecialization =
true;
291 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
298 if (isa<FunctionTemplateDecl>(TD)) {
304 assert(isa<ClassTemplateDecl>(TD) || isa<TemplateTemplateParmDecl>(TD) ||
305 isa<TypeAliasTemplateDecl>(TD) || isa<VarTemplateDecl>(TD) ||
306 isa<BuiltinTemplateDecl>(TD) || isa<ConceptDecl>(TD));
321 bool MemberOfUnknownSpecialization =
false;
329 MemberOfUnknownSpecialization))
332 if (R.
empty())
return false;
366 Diag(IILoc, diag::err_template_kw_missing)
378 bool EnteringContext,
379 bool &MemberOfUnknownSpecialization,
382 bool AllowTypoCorrection) {
392 MemberOfUnknownSpecialization =
false;
394 bool IsDependent =
false;
395 if (!ObjectType.
isNull()) {
398 assert(SS.
isEmpty() &&
"ObjectType and scope specifier cannot coexist");
404 "Caller should have completed object type");
436 bool ObjectTypeSearchedInScope =
false;
437 bool AllowFunctionTemplatesInLookup =
true;
469 if (!ObjectType.
isNull()) {
473 AllowFunctionTemplatesInLookup =
false;
474 ObjectTypeSearchedInScope =
true;
497 if (AllFunctions || (Found.
empty() && !IsDependent)) {
509 if (Found.
empty() && !IsDependent && AllowTypoCorrection) {
517 FilterCCC.WantExpressionKeywords =
false;
518 FilterCCC.WantRemainingKeywords =
false;
519 FilterCCC.WantCXXNamedCasts =
true;
523 if (
auto *ND = Corrected.getFoundDecl())
528 }
else if (!Found.
empty()) {
531 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
532 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
533 Name.getAsString() == CorrectedStr;
535 << Name << LookupCtx << DroppedSpecifier
549 MemberOfUnknownSpecialization =
true;
555 if (ExampleLookupResult && RequiredTemplate) {
556 Diag(Found.
getNameLoc(), diag::err_template_kw_refers_to_non_template)
561 diag::note_template_kw_refers_to_non_template)
569 if (S && !ObjectType.
isNull() && !ObjectTypeSearchedInScope &&
586 if (FoundOuter.
empty()) {
604 diag::ext_nested_name_member_ref_lookup_ambiguous)
608 diag::note_ambig_member_ref_object_type)
611 diag::note_ambig_member_ref_scope);
634 bool MissingTemplateKeyword =
false;
637 if (
auto *DRE = dyn_cast<DeclRefExpr>(
TemplateName.get())) {
638 NameInfo = DRE->getNameInfo();
639 SS.
Adopt(DRE->getQualifierLoc());
641 Found = DRE->getFoundDecl();
642 }
else if (
auto *ME = dyn_cast<MemberExpr>(
TemplateName.get())) {
643 NameInfo = ME->getMemberNameInfo();
644 SS.
Adopt(ME->getQualifierLoc());
646 LookupCtx = ME->getBase()->getType()->getAsCXXRecordDecl();
647 Found = ME->getMemberDecl();
648 }
else if (
auto *DSDRE =
649 dyn_cast<DependentScopeDeclRefExpr>(
TemplateName.get())) {
650 NameInfo = DSDRE->getNameInfo();
651 SS.
Adopt(DSDRE->getQualifierLoc());
652 MissingTemplateKeyword =
true;
653 }
else if (
auto *DSME =
654 dyn_cast<CXXDependentScopeMemberExpr>(
TemplateName.get())) {
655 NameInfo = DSME->getMemberNameInfo();
656 SS.
Adopt(DSME->getQualifierLoc());
657 MissingTemplateKeyword =
true;
659 llvm_unreachable(
"unexpected kind of potential template name");
664 if (MissingTemplateKeyword) {
673 TemplateCandidateFilter(
Sema &S) : S(S) {
674 WantTypeSpecifiers =
false;
675 WantExpressionKeywords =
false;
676 WantRemainingKeywords =
false;
677 WantCXXNamedCasts =
true;
679 bool ValidateCandidate(
const TypoCorrection &Candidate)
override {
685 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
686 return std::make_unique<TemplateCandidateFilter>(*
this);
691 TemplateCandidateFilter CCC(*
this);
694 auto *ND = Corrected.getFoundDecl();
697 if (ND || Corrected.isKeyword()) {
699 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
700 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
701 Name.getAsString() == CorrectedStr;
703 PDiag(diag::err_non_template_in_member_template_id_suggest)
704 << Name << LookupCtx << DroppedSpecifier
708 PDiag(diag::err_non_template_in_template_id_suggest)
713 diag::note_non_template_in_template_id_found);
718 Diag(NameInfo.
getLoc(), diag::err_non_template_in_template_id)
721 Diag(Found->
getLocation(), diag::note_non_template_in_template_id_found);
731 bool isAddressOfOperand,
746 bool MightBeCxx11UnevalField =
752 IsEnum = isa_and_nonnull<EnumType>(NNS->getAsType());
754 if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
755 isa<CXXMethodDecl>(DC) && cast<CXXMethodDecl>(DC)->isInstance()) {
756 QualType ThisType = cast<CXXMethodDecl>(DC)->getThisType();
760 NamedDecl *FirstQualifierInScope =
nullptr;
763 Context,
nullptr, ThisType,
true,
765 FirstQualifierInScope, NameInfo, TemplateArgs);
782 Context, QualifierLoc, TemplateKWLoc, NameInfo, TemplateArgs);
790 bool InstantiatedFromMember,
795 assert(isa<TagDecl>(Instantiation) || isa<FunctionDecl>(Instantiation) ||
796 isa<VarDecl>(Instantiation));
798 bool IsEntityBeingDefined =
false;
799 if (
const TagDecl *TD = dyn_cast_or_null<TagDecl>(PatternDef))
800 IsEntityBeingDefined = TD->isBeingDefined();
802 if (PatternDef && !IsEntityBeingDefined) {
817 if (!Complain || (PatternDef && PatternDef->
isInvalidDecl()))
820 std::optional<unsigned>
Note;
822 if (
TagDecl *TD = dyn_cast<TagDecl>(Instantiation))
825 Diag(PointOfInstantiation,
826 diag::err_template_instantiate_within_definition)
832 }
else if (InstantiatedFromMember) {
833 if (isa<FunctionDecl>(Instantiation)) {
834 Diag(PointOfInstantiation,
835 diag::err_explicit_instantiation_undefined_member)
838 Note = diag::note_explicit_instantiation_here;
840 assert(isa<TagDecl>(Instantiation) &&
"Must be a TagDecl!");
841 Diag(PointOfInstantiation,
842 diag::err_implicit_instantiate_member_undefined)
844 Note = diag::note_member_declared_at;
847 if (isa<FunctionDecl>(Instantiation)) {
848 Diag(PointOfInstantiation,
849 diag::err_explicit_instantiation_undefined_func_template)
851 Note = diag::note_explicit_instantiation_here;
852 }
else if (isa<TagDecl>(Instantiation)) {
853 Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)
856 Note = diag::note_template_decl_here;
858 assert(isa<VarDecl>(Instantiation) &&
"Must be a VarDecl!");
859 if (isa<VarTemplateSpecializationDecl>(Instantiation)) {
860 Diag(PointOfInstantiation,
861 diag::err_explicit_instantiation_undefined_var_template)
865 Diag(PointOfInstantiation,
866 diag::err_explicit_instantiation_undefined_member)
869 Note = diag::note_explicit_instantiation_here;
896 unsigned DiagId =
getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
897 : diag::err_template_param_shadow;
898 Diag(Loc, DiagId) << cast<NamedDecl>(PrevDecl)->getDeclName();
906 if (
TemplateDecl *Temp = dyn_cast_or_null<TemplateDecl>(D)) {
907 D = Temp->getTemplatedDecl();
916 "Only template template arguments can be pack expansions here");
917 assert(
getAsTemplate().get().containsUnexpandedParameterPack() &&
918 "Template template argument pack expansion without packs");
920 Result.EllipsisLoc = EllipsisLoc;
955 llvm_unreachable(
"Unhandled parsed template argument");
962 for (
unsigned I = 0,
Last = TemplateArgsIn.size(); I !=
Last; ++I)
985 assert(TInfo &&
"template argument with no location");
993 EllipsisLoc = PET.getEllipsisLoc();
994 TL = PET.getPatternLoc();
999 SS.
Adopt(ET.getQualifierLoc());
1000 TL = ET.getNamedTypeLoc();
1004 TemplateName Name = DTST.getTypePtr()->getTemplateName();
1010 DTST.getTemplateNameLoc());
1040 unsigned Depth,
unsigned Position,
1043 bool HasTypeConstraint) {
1044 assert(S->isTemplateParamScope() &&
1045 "Template type parameter not in template parameter scope!");
1047 bool IsParameterPack = EllipsisLoc.
isValid();
1050 KeyLoc, ParamNameLoc, Depth, Position,
1051 ParamName, Typename, IsParameterPack,
1057 LSI->LocalPacks.push_back(Param);
1070 if (DefaultArg && IsParameterPack) {
1071 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1072 DefaultArg =
nullptr;
1080 assert(DefaultTInfo &&
"expected source information for type");
1107 return TemplateArgs;
1120 diag::err_type_constraint_non_type_concept);
1126 if (!WereArgsSpecified &&
1129 diag::err_type_constraint_missing_arguments)
1148 bool AllowUnexpandedPack) {
1164 if (EllipsisLoc.
isInvalid() && !AllowUnexpandedPack) {
1175 ConstrainedParameter, EllipsisLoc);
1178template<
typename ArgumentLocAppender>
1193 Appender(ConstraintArgs);
1202 NamedConcept, NamedConcept, &ConstraintArgs);
1204 return ImmediatelyDeclaredConstraint;
1220 ImmediatelyDeclaredConstraint.
get(), BO_LAnd,
1221 EllipsisLoc,
nullptr,
1241 *TemplateArgs) :
nullptr;
1247 *
this,
NS, NameInfo, NamedConcept,
1250 ParamAsArgument, ConstrainedParameter->
getLocation(),
1253 for (const auto &ArgLoc : TemplateArgs->arguments())
1254 ConstraintArgs.addArgument(ArgLoc);
1256 if (ImmediatelyDeclaredConstraint.
isInvalid())
1261 NamedConcept, ArgsAsWritten,
1262 ImmediatelyDeclaredConstraint.
get());
1273 diag::err_unsupported_placeholder_constraint)
1291 for (unsigned I = 0, C = TL.getNumArgs(); I != C; ++I)
1292 ConstraintArgs.addArgument(TL.getArgLoc(I));
1295 if (ImmediatelyDeclaredConstraint.
isInvalid() ||
1296 !ImmediatelyDeclaredConstraint.
isUsable())
1300 ImmediatelyDeclaredConstraint.
get());
1338 Diag(Loc, diag::err_template_nontype_parm_rvalue_ref) << T;
1348 Diag(Loc, diag::err_template_nontype_parm_bad_type) << T;
1356 Diag(Loc, diag::err_template_nontype_parm_not_structural) << T;
1363 for (
const FieldDecl *FD : RD->fields()) {
1365 Diag(FD->getLocation(), diag::note_not_structural_non_public) << T << 0;
1368 if (FD->isMutable()) {
1369 Diag(FD->getLocation(), diag::note_not_structural_mutable_field) << T;
1372 if (FD->getType()->isRValueReferenceType()) {
1373 Diag(FD->getLocation(), diag::note_not_structural_rvalue_ref_field)
1380 for (
const auto &BaseSpec : RD->bases()) {
1381 if (BaseSpec.getAccessSpecifier() !=
AS_public) {
1382 Diag(BaseSpec.getBaseTypeLoc(), diag::note_not_structural_non_public)
1393 for (
const FieldDecl *FD : RD->fields()) {
1396 SubLoc = FD->getLocation();
1404 for (
const auto &BaseSpec : RD->bases()) {
1407 SubLoc = BaseSpec.getBaseTypeLoc();
1415 assert(Kind != -1 &&
"couldn't find reason why type is not structural");
1416 Diag(SubLoc, diag::note_not_structural_subobject)
1417 << T << Kind << SubType;
1430 Diag(Loc, diag::err_variably_modified_nontype_template_param)
1483 Diag(Loc, diag::err_template_nontype_parm_bad_structural_type) << T;
1487 Diag(Loc, diag::warn_cxx17_compat_template_nontype_parm_type) << T;
1499 auto CheckValidDeclSpecifiers = [
this, &D] {
1513 Diag(Loc, diag::err_invalid_decl_specifier_in_nontype_parm)
1550 CheckValidDeclSpecifiers();
1553 if (isa<AutoType>(T))
1555 diag::warn_cxx14_compat_template_nontype_parm_auto_type)
1558 assert(S->isTemplateParamScope() &&
1559 "Non-type template parameter not in template parameter scope!");
1579 if (TL.isConstrained())
1588 LSI->LocalPacks.push_back(Param);
1602 if (
Default && IsParameterPack) {
1603 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1632 assert(S->isTemplateParamScope() &&
1633 "Template template parameter not in template parameter scope!");
1636 bool IsParameterPack = EllipsisLoc.
isValid();
1640 Depth, Position, IsParameterPack,
1646 LSI->LocalPacks.push_back(Param);
1657 if (Params->
size() == 0) {
1666 if (IsParameterPack && !
Default.isInvalid()) {
1667 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1682 Diag(DefaultArg.
getLocation(), diag::err_template_arg_not_valid_template)
1700class ConstraintRefersToContainingTemplateChecker
1701 :
public TreeTransform<ConstraintRefersToContainingTemplateChecker> {
1702 bool Result =
false;
1704 unsigned TemplateDepth = 0;
1708 void CheckIfContainingRecord(
const CXXRecordDecl *CheckingRD) {
1713 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
1714 if (CheckingRD == RD->getMostRecentDecl())
1719 assert(D->
getDepth() <= TemplateDepth &&
1720 "Nothing should reference a value below the actual template depth, "
1721 "depth is likely wrong");
1722 if (D->
getDepth() != TemplateDepth)
1733 ConstraintRefersToContainingTemplateChecker(
Sema &SemaRef,
1735 unsigned TemplateDepth)
1736 : inherited(SemaRef), Friend(Friend), TemplateDepth(TemplateDepth) {}
1737 bool getResult()
const {
return Result; }
1743 using inherited::TransformTemplateTypeParmType;
1747 "Nothing should reference a value below the actual template depth, "
1748 "depth is likely wrong");
1751 return inherited::TransformTemplateTypeParmType(
1763 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
1764 TransformType(TD->getUnderlyingType());
1765 else if (
auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(D))
1766 CheckNonTypeTemplateParmDecl(NTTPD);
1767 else if (
auto *VD = dyn_cast<ValueDecl>(D))
1768 TransformType(VD->getType());
1769 else if (
auto *TD = dyn_cast<TemplateDecl>(D))
1770 TransformTemplateParameterList(TD->getTemplateParameters());
1771 else if (
auto *RD = dyn_cast<CXXRecordDecl>(D))
1772 CheckIfContainingRecord(RD);
1773 else if (isa<NamedDecl>(D)) {
1776 llvm_unreachable(
"Don't know how to handle this declaration type yet");
1784 const Expr *Constraint) {
1786 ConstraintRefersToContainingTemplateChecker Checker(*
this, Friend,
1788 Checker.TransformExpr(
const_cast<Expr *
>(Constraint));
1789 return Checker.getResult();
1802 Expr *RequiresClause) {
1804 Diag(ExportLoc, diag::warn_template_export_unsupported);
1810 Context, TemplateLoc, LAngleLoc,
1811 llvm::ArrayRef(Params.data(), Params.size()), RAngleLoc, RequiresClause);
1827 assert(TemplateParams && TemplateParams->
size() > 0 &&
1828 "No template parameters");
1829 assert(TUK !=
TUK_Reference &&
"Can only declare or define class templates");
1837 assert(Kind !=
TTK_Enum &&
"can't build template of enumerated type");
1841 Diag(KWLoc, diag::err_template_unnamed_class);
1855 if (!SemanticContext) {
1860 ? diag::warn_template_qualified_friend_ignored
1861 : diag::err_template_qualified_declarator_no_match)
1900 PrevDecl = (*
Previous.begin())->getUnderlyingDecl();
1912 dyn_cast_or_null<ClassTemplateDecl>(PrevDecl);
1917 if (!PrevClassTemplate && PrevDecl && isa<CXXRecordDecl>(PrevDecl) &&
1918 cast<CXXRecordDecl>(PrevDecl)->isInjectedClassName()) {
1921 = cast<CXXRecordDecl>(PrevDecl)->getDescribedClassTemplate();
1922 if (!PrevClassTemplate && isa<ClassTemplateSpecializationDecl>(PrevDecl)) {
1924 = cast<ClassTemplateSpecializationDecl>(PrevDecl)
1925 ->getSpecializedTemplate();
1948 PrevDecl = PrevClassTemplate =
nullptr;
1949 SemanticContext = OutermostContext;
1963 PrevDecl = (*
Previous.begin())->getUnderlyingDecl();
1966 }
else if (PrevDecl &&
1969 PrevDecl = PrevClassTemplate =
nullptr;
1971 if (
auto *Shadow = dyn_cast_or_null<UsingShadowDecl>(
1972 PrevDecl ?
Previous.getRepresentativeDecl() :
nullptr)) {
1974 !(PrevClassTemplate &&
1977 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
1978 Diag(Shadow->getTargetDecl()->getLocation(),
1979 diag::note_using_decl_target);
1980 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) << 0;
1982 PrevDecl = PrevClassTemplate =
nullptr;
1986 if (PrevClassTemplate) {
2005 Diag(KWLoc, diag::err_use_with_wrong_tag)
2021 auto *Tmpl = cast<CXXRecordDecl>(Hidden)->getDescribedClassTemplate();
2022 assert(Tmpl &&
"original definition of a class template is not a "
2027 Diag(NameLoc, diag::err_redefinition) << Name;
2028 Diag(Def->getLocation(), diag::note_previous_definition);
2035 }
else if (PrevDecl) {
2041 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
2056 (SS.
isSet() && SemanticContext && SemanticContext->
isRecord() &&
2067 Diag(NameLoc, TUK ==
TUK_Friend ? diag::err_friend_decl_does_not_match
2068 : diag::err_member_decl_does_not_match)
2069 << Name << SemanticContext <<
true << SS.
getRange();
2079 bool ShouldAddRedecl
2084 PrevClassTemplate && ShouldAddRedecl ?
2088 if (NumOuterTemplateParamLists > 0)
2091 llvm::ArrayRef(OuterTemplateParamLists, NumOuterTemplateParamLists));
2105 if (ShouldAddRedecl)
2110 if (ModulePrivateLoc.
isValid())
2116 assert(T->
isDependentType() &&
"Class template type is not dependent?");
2121 if (PrevClassTemplate &&
2138 if (PrevClassTemplate)
2173 if (PrevClassTemplate)
2192class ExtractTypeForDeductionGuide
2198 ExtractTypeForDeductionGuide(
2201 :
Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
2206 ASTContext &Context = SemaRef.getASTContext();
2216 if (isa<TypeAliasDecl>(OrigDecl))
2221 assert(isa<TypedefDecl>(OrigDecl) &&
"Not a Type alias or typedef");
2226 MaterializedTypedefs.push_back(
Decl);
2239struct ConvertConstructorToDeductionGuideTransform {
2240 ConvertConstructorToDeductionGuideTransform(
Sema &S,
2242 : SemaRef(S), Template(Template) {}
2276 AllParams.reserve(TemplateParams->
size() + InnerParams->
size());
2277 AllParams.insert(AllParams.begin(),
2278 TemplateParams->
begin(), TemplateParams->
end());
2279 SubstArgs.reserve(InnerParams->
size());
2285 Args.
setKind(TemplateSubstitutionKind::Rewrite);
2288 NamedDecl *NewParam = transformTemplateParameter(Param, Args);
2291 AllParams.push_back(NewParam);
2297 Expr *RequiresClause =
nullptr;
2298 if (
Expr *InnerRC = InnerParams->getRequiresClause()) {
2300 Args.
setKind(TemplateSubstitutionKind::Rewrite);
2309 TemplateParams = TemplateParameterList::Create(
2310 SemaRef.
Context, InnerParams->getTemplateLoc(),
2311 InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
2319 Args.
setKind(TemplateSubstitutionKind::Rewrite);
2327 assert(FPTL &&
"no prototype for constructor declaration");
2335 QualType NewType = transformFunctionProtoType(TLB, FPTL, Params, Args,
2336 MaterializedTypedefs);
2354 DeductionGuideName, EPI);
2362 for (
auto T : ParamTypes) {
2364 SemaRef.
Context, DC, Loc, Loc,
nullptr, T,
2367 FPTL.
setParam(Params.size(), NewParam);
2368 Params.push_back(NewParam);
2381 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(
TemplateParam)) {
2385 SemaRef.
Context, DC, TTP->getBeginLoc(), TTP->getLocation(),
2386 0, Depth1IndexAdjustment + TTP->getIndex(),
2387 TTP->getIdentifier(), TTP->wasDeclaredWithTypename(),
2388 TTP->isParameterPack(), TTP->hasTypeConstraint(),
2389 TTP->isExpandedParameterPack()
2390 ? std::optional<unsigned>(TTP->getNumExpansionParameters())
2392 if (
const auto *TC = TTP->getTypeConstraint())
2395 if (TTP->hasDefaultArgument()) {
2397 SemaRef.
SubstType(TTP->getDefaultArgumentInfo(), Args,
2398 TTP->getDefaultArgumentLoc(), TTP->getDeclName());
2399 if (InstantiatedDefaultArg)
2400 NewTTP->setDefaultArgument(InstantiatedDefaultArg);
2407 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(
TemplateParam))
2408 return transformTemplateParameterImpl(TTP, Args);
2410 return transformTemplateParameterImpl(
2413 template<
typename TemplateParmDecl>
2415 transformTemplateParameterImpl(TemplateParmDecl *OldParam,
2420 cast<TemplateParmDecl>(SemaRef.
SubstDecl(OldParam, DC, Args));
2421 assert(NewParam->getDepth() == 0 &&
"unexpected template param depth");
2422 NewParam->setPosition(NewParam->getPosition() + Depth1IndexAdjustment);
2426 QualType transformFunctionProtoType(
2437 transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
2440 ParamTypes.push_back(NewParam->
getType());
2441 Params.push_back(NewParam);
2463 ReturnType, ParamTypes, TL.
getBeginLoc(), DeductionGuideName, EPI);
2464 if (Result.isNull())
2473 for (
unsigned I = 0, E = NewTL.
getNumParams(); I != E; ++I)
2488 SemaRef.
SubstType(PackTL.getPatternLoc(), Args,
2490 if (!NewDI)
return nullptr;
2493 PackTL.getTypePtr()->getNumExpansions());
2504 NewDI = ExtractTypeForDeductionGuide(SemaRef, MaterializedTypedefs)
2514 NewDefArg =
new (SemaRef.
Context)
2548 TInfo->
getType(), TInfo, LocEnd, Ctor);
2549 Guide->setImplicit();
2550 Guide->setParams(Params);
2552 for (
auto *Param : Params)
2553 Param->setDeclContext(Guide);
2554 for (
auto *TD : MaterializedTypedefs)
2555 TD->setDeclContext(Guide);
2558 SemaRef.
Context, DC, Loc, DeductionGuideName, TemplateParams, Guide);
2559 GuideTemplate->setImplicit();
2560 Guide->setDescribedFunctionTemplate(GuideTemplate);
2562 if (isa<CXXRecordDecl>(DC)) {
2568 return GuideTemplate;
2577 TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate();
2578 Template = DescribedTemplate ? DescribedTemplate : Template;
2585 ConvertConstructorToDeductionGuideTransform Transform(
2586 *
this, cast<ClassTemplateDecl>(Template));
2592 auto Existing = DC->
lookup(Transform.DeductionGuideName);
2593 for (
auto *D : Existing)
2605 if (BuildingDeductionGuides.
isInvalid())
2613 bool AddedAny =
false;
2615 D = D->getUnderlyingDecl();
2624 if (ProcessedCtors.count(D))
2627 auto *FTD = dyn_cast<FunctionTemplateDecl>(D);
2637 return !P || P->hasUnparsedDefaultArg();
2641 ProcessedCtors.insert(D);
2642 Transform.transformConstructor(FTD, CD);
2651 Transform.buildSimpleDeductionGuide(std::nullopt);
2655 cast<CXXDeductionGuideDecl>(
2656 cast<FunctionTemplateDecl>(
2657 Transform.buildSimpleDeductionGuide(Transform.DeducedType))
2658 ->getTemplatedDecl())
2659 ->setIsCopyDeductionCandidate();
2687 diag::warn_cxx98_compat_template_parameter_default_in_function_template
2688 : diag::ext_template_parameter_default_in_function_template)
2697 S.
Diag(ParamLoc, diag::err_template_parameter_default_template_member)
2706 S.
Diag(ParamLoc, diag::err_template_parameter_default_friend_template)
2715 llvm_unreachable(
"Invalid TemplateParamListContext!");
2728 for (
unsigned I = 0, N = Params->
size(); I != N; ++I) {
2733 if (TC->hasExplicitTemplateArgs())
2734 for (
auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
2742 if (!NTTP->isParameterPack() &&
2744 NTTP->getTypeSourceInfo(),
2752 = dyn_cast<TemplateTemplateParmDecl>(
P))
2800 bool SawDefaultArgument =
false;
2806 OldParam = OldParams->
begin();
2808 bool RemoveDefaultArguments =
false;
2810 NewParamEnd = NewParams->
end();
2811 NewParam != NewParamEnd; ++NewParam) {
2814 bool RedundantDefaultArg =
false;
2817 bool InconsistentDefaultArg =
false;
2819 std::string PrevModuleName;
2825 bool MissingDefaultArg =
false;
2828 bool SawParameterPack =
false;
2831 = dyn_cast<TemplateTypeParmDecl>(*NewParam)) {
2833 if (NewTypeParm->hasDefaultArgument() &&
2835 NewTypeParm->getLocation(),
2836 NewTypeParm->getDefaultArgumentInfo()->getTypeLoc()
2838 NewTypeParm->removeDefaultArgument();
2842 = OldParams? cast<TemplateTypeParmDecl>(*OldParam) :
nullptr;
2843 if (NewTypeParm->isParameterPack()) {
2844 assert(!NewTypeParm->hasDefaultArgument() &&
2845 "Parameter packs can't have a default argument!");
2846 SawParameterPack =
true;
2848 NewTypeParm->hasDefaultArgument() &&
2851 NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
2852 SawDefaultArgument =
true;
2855 RedundantDefaultArg =
true;
2856 else if (!
getASTContext().isSameDefaultTemplateArgument(OldTypeParm,
2858 InconsistentDefaultArg =
true;
2862 PreviousDefaultArgLoc = NewDefaultLoc;
2866 NewTypeParm->setInheritedDefaultArgument(
Context, OldTypeParm);
2868 }
else if (NewTypeParm->hasDefaultArgument()) {
2869 SawDefaultArgument =
true;
2870 PreviousDefaultArgLoc = NewTypeParm->getDefaultArgumentLoc();
2871 }
else if (SawDefaultArgument)
2872 MissingDefaultArg =
true;
2874 = dyn_cast<NonTypeTemplateParmDecl>(*NewParam)) {
2876 if (!NewNonTypeParm->isParameterPack() &&
2878 NewNonTypeParm->getTypeSourceInfo(),
2885 if (NewNonTypeParm->hasDefaultArgument() &&
2887 NewNonTypeParm->getLocation(),
2888 NewNonTypeParm->getDefaultArgument()->getSourceRange())) {
2889 NewNonTypeParm->removeDefaultArgument();
2894 = OldParams? cast<NonTypeTemplateParmDecl>(*OldParam) :
nullptr;
2895 if (NewNonTypeParm->isParameterPack()) {
2896 assert(!NewNonTypeParm->hasDefaultArgument() &&
2897 "Parameter packs can't have a default argument!");
2898 if (!NewNonTypeParm->isPackExpansion())
2899 SawParameterPack =
true;
2901 NewNonTypeParm->hasDefaultArgument() &&
2904 NewDefaultLoc = NewNonTypeParm->getDefaultArgumentLoc();
2905 SawDefaultArgument =
true;
2907 RedundantDefaultArg =
true;
2909 OldNonTypeParm, NewNonTypeParm)) {
2910 InconsistentDefaultArg =
true;
2914 PreviousDefaultArgLoc = NewDefaultLoc;
2918 NewNonTypeParm->setInheritedDefaultArgument(
Context, OldNonTypeParm);
2920 }
else if (NewNonTypeParm->hasDefaultArgument()) {
2921 SawDefaultArgument =
true;
2922 PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc();
2923 }
else if (SawDefaultArgument)
2924 MissingDefaultArg =
true;
2927 = cast<TemplateTemplateParmDecl>(*NewParam);
2944 = OldParams? cast<TemplateTemplateParmDecl>(*OldParam) :
nullptr;
2947 "Parameter packs can't have a default argument!");
2949 SawParameterPack =
true;
2950 }
else if (OldTemplateParm &&
2956 SawDefaultArgument =
true;
2958 RedundantDefaultArg =
true;
2960 OldTemplateParm, NewTemplateParm)) {
2961 InconsistentDefaultArg =
true;
2965 PreviousDefaultArgLoc = NewDefaultLoc;
2970 PreviousDefaultArgLoc
2973 SawDefaultArgument =
true;
2974 PreviousDefaultArgLoc
2976 }
else if (SawDefaultArgument)
2977 MissingDefaultArg =
true;
2983 if (SawParameterPack && (NewParam + 1) != NewParamEnd &&
2986 Diag((*NewParam)->getLocation(),
2987 diag::err_template_param_pack_must_be_last_template_parameter);
3004 if (RedundantDefaultArg) {
3005 Diag(NewDefaultLoc, diag::err_template_param_default_arg_redefinition);
3006 Diag(OldDefaultLoc, diag::note_template_param_prev_default_arg);
3008 }
else if (InconsistentDefaultArg) {
3012 diag::err_template_param_default_arg_inconsistent_redefinition);
3014 diag::note_template_param_prev_default_arg_in_other_module)
3023 Diag((*NewParam)->getLocation(),
3024 diag::err_template_param_default_arg_missing);
3025 Diag(PreviousDefaultArgLoc, diag::note_template_param_prev_default_arg);
3027 RemoveDefaultArguments =
true;
3038 if (RemoveDefaultArguments) {
3040 NewParamEnd = NewParams->
end();
3041 NewParam != NewParamEnd; ++NewParam) {
3043 TTP->removeDefaultArgument();
3045 = dyn_cast<NonTypeTemplateParmDecl>(*NewParam))
3046 NTTP->removeDefaultArgument();
3048 cast<TemplateTemplateParmDecl>(*NewParam)->removeDefaultArgument();
3068 bool IgnoreNonTypeDependent;
3073 DependencyChecker(
unsigned Depth,
bool IgnoreNonTypeDependent)
3074 : Depth(Depth), IgnoreNonTypeDependent(IgnoreNonTypeDependent),
3078 : IgnoreNonTypeDependent(IgnoreNonTypeDependent), Match(
false) {
3081 Depth = PD->getDepth();
3083 dyn_cast<NonTypeTemplateParmDecl>(ND)) {
3084 Depth = PD->getDepth();
3086 Depth = cast<TemplateTemplateParmDecl>(ND)->getDepth();
3091 if (ParmDepth >= Depth) {
3099 bool TraverseStmt(
Stmt *S, DataRecursionQueue *Q =
nullptr) {
3104 if (
auto *E = dyn_cast_or_null<Expr>(S))
3105 if (IgnoreNonTypeDependent && !E->isTypeDependent())
3107 return super::TraverseStmt(S, Q);
3110 bool TraverseTypeLoc(
TypeLoc TL) {
3111 if (IgnoreNonTypeDependent && !TL.
isNull() &&
3114 return super::TraverseTypeLoc(TL);
3123 return IgnoreNonTypeDependent || !Matches(T->
getDepth());
3129 if (Matches(PD->getDepth()))
3131 return super::TraverseTemplateName(N);
3136 dyn_cast<NonTypeTemplateParmDecl>(E->
getDecl()))
3137 if (Matches(PD->getDepth(), E->
getExprLoc()))
3139 return super::VisitDeclRefExpr(E);
3161 if (!Params->
size())
3164 DependencyChecker Checker(Params,
false);
3165 Checker.TraverseType(T);
3166 return Checker.Match;
3176 if (
const Type *CurType = NNS->getAsType()) {
3225 bool &IsMemberSpecialization,
bool &
Invalid,
bool SuppressDiagnostic) {
3226 IsMemberSpecialization =
false;
3248 NestedTypes.push_back(T);
3254 = dyn_cast<ClassTemplateSpecializationDecl>(Record)) {
3255 if (!isa<ClassTemplatePartialSpecializationDecl>(Spec) &&
3257 ExplicitSpecLoc = Spec->getLocation();
3260 }
else if (Record->getTemplateSpecializationKind()
3262 ExplicitSpecLoc = Record->getLocation();
3275 if (
TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
3321 std::reverse(NestedTypes.begin(), NestedTypes.end());
3329 bool SawNonEmptyTemplateParameterList =
false;
3331 auto CheckExplicitSpecialization = [&](
SourceRange Range,
bool Recovery) {
3332 if (SawNonEmptyTemplateParameterList) {
3333 if (!SuppressDiagnostic)
3334 Diag(DeclLoc, diag::err_specialize_member_of_template)
3335 << !Recovery << Range;
3337 IsMemberSpecialization =
false;
3344 auto DiagnoseMissingExplicitSpecialization = [&] (
SourceRange Range) {
3346 if (CheckExplicitSpecialization(Range,
true))
3351 if (!ParamLists.empty())
3352 ExpectedTemplateLoc = ParamLists[0]->getTemplateLoc();
3354 ExpectedTemplateLoc = DeclStartLoc;
3356 if (!SuppressDiagnostic)
3357 Diag(DeclLoc, diag::err_template_spec_needs_header)
3364 for (
unsigned TypeIdx = 0, NumTypes = NestedTypes.size(); TypeIdx != NumTypes;
3366 T = NestedTypes[TypeIdx];
3369 bool NeedEmptyTemplateHeader =
false;
3372 bool NeedNonemptyTemplateHeader =
false;
3385 = dyn_cast<ClassTemplatePartialSpecializationDecl>(Record)) {
3386 ExpectedTemplateParams = Partial->getTemplateParameters();
3387 NeedNonemptyTemplateHeader =
true;
3388 }
else if (Record->isDependentType()) {
3389 if (Record->getDescribedClassTemplate()) {
3390 ExpectedTemplateParams = Record->getDescribedClassTemplate()
3391 ->getTemplateParameters();
3392 NeedNonemptyTemplateHeader =
true;
3395 = dyn_cast<ClassTemplateSpecializationDecl>(Record)) {
3401 NeedEmptyTemplateHeader =
true;
3404 }
else if (Record->getTemplateSpecializationKind()) {
3405 if (Record->getTemplateSpecializationKind()
3407 TypeIdx == NumTypes - 1)
3408 IsMemberSpecialization =
true;
3414 if (
TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
3416 NeedNonemptyTemplateHeader =
true;
3421 NeedNonemptyTemplateHeader =
false;
3431 if (
ParamIdx < ParamLists.size()) {
3432 if (ParamLists[
ParamIdx]->size() == 0) {
3433 if (CheckExplicitSpecialization(ParamLists[
ParamIdx]->getSourceRange(),
3437 SawNonEmptyTemplateParameterList =
true;
3440 if (NeedEmptyTemplateHeader) {
3443 if (TypeIdx == NumTypes - 1)
3444 IsMemberSpecialization =
true;
3446 if (
ParamIdx < ParamLists.size()) {
3447 if (ParamLists[
ParamIdx]->size() > 0) {
3449 if (!SuppressDiagnostic)
3451 diag::err_template_param_list_matches_nontemplate)
3454 ParamLists[
ParamIdx]->getRAngleLoc())
3466 if (DiagnoseMissingExplicitSpecialization(
3473 if (NeedNonemptyTemplateHeader) {
3479 if (
ParamIdx < ParamLists.size() &&
3481 ExpectedTemplateParams =
nullptr;
3486 if (
ParamIdx < ParamLists.size()) {
3488 if (ExpectedTemplateParams &&
3490 ExpectedTemplateParams,
3503 if (!SuppressDiagnostic)
3504 Diag(DeclLoc, diag::err_template_spec_needs_template_parameters)
3515 if (
ParamIdx >= ParamLists.size()) {
3516 if (TemplateId && !IsFriend) {
3532 if (
ParamIdx < ParamLists.size() - 1) {
3533 bool HasAnyExplicitSpecHeader =
false;
3534 bool AllExplicitSpecHeaders =
true;
3535 for (
unsigned I =
ParamIdx, E = ParamLists.size() - 1; I != E; ++I) {
3536 if (ParamLists[I]->size() == 0)
3537 HasAnyExplicitSpecHeader =
true;
3539 AllExplicitSpecHeaders =
false;
3542 if (!SuppressDiagnostic)
3544 AllExplicitSpecHeaders ? diag::warn_template_spec_extra_headers
3545 : diag::err_template_spec_extra_headers)
3547 ParamLists[ParamLists.size() - 2]->getRAngleLoc());
3552 if (ExplicitSpecLoc.
isValid() && HasAnyExplicitSpecHeader &&
3553 !SuppressDiagnostic)
3554 Diag(ExplicitSpecLoc,
3555 diag::note_explicit_template_spec_does_not_need_header)
3556 << NestedTypes.back();
3561 if (!AllExplicitSpecHeaders)
3572 if (ParamLists.back()->size() == 0 &&
3573 CheckExplicitSpecialization(ParamLists[
ParamIdx]->getSourceRange(),
3579 return ParamLists.back();
3583 if (
TemplateDecl *Template = Name.getAsTemplateDecl()) {
3585 << (isa<FunctionTemplateDecl>(Template)
3587 : isa<ClassTemplateDecl>(Template)
3589 : isa<VarTemplateDecl>(Template)
3591 : isa<TypeAliasTemplateDecl>(Template) ? 3 : 4)
3600 Diag((*I)->getLocation(), diag::note_template_declared_here)
3601 << 0 << (*I)->getDeclName();
3619 QualType OrigType = Converted[1].getAsType();
3623 SemaRef.
Diag(TemplateArgs[1].getLocation(),
3624 diag::err_integer_sequence_integral_element_type);
3639 OrigType, TemplateArgs[1].getLocation())));
3641 if (llvm::APSInt NumArgs = NumArgsArg.
getAsIntegral(); NumArgs >= 0) {
3643 for (llvm::APSInt I(NumArgs.getBitWidth(), NumArgs.isUnsigned());
3647 TA, OrigType, TemplateArgs[2].getLocation()));
3652 SemaRef.
Diag(TemplateArgs[2].getLocation(),
3653 diag::err_integer_sequence_negative_length);
3660 TemplateLoc, SyntheticTemplateArgs);
3667 assert(Converted.size() == 2 &&
3668 "__type_pack_element should be given an index and a parameter pack");
3676 assert(Index >= 0 &&
"the index used with __type_pack_element should be of "
3677 "type std::size_t, and hence be non-negative");
3679 if (Index >= Ts.pack_size()) {
3680 SemaRef.
Diag(TemplateArgs[0].getLocation(),
3681 diag::err_type_pack_element_out_of_bounds);
3686 int64_t N = Index.getExtValue();
3687 return Ts.getPackAsArray()[N].getAsType();
3689 llvm_unreachable(
"unexpected BuiltinTemplateDecl!");
3708 if (BinOp->getOpcode() == BO_LAnd) {
3715 Terms.push_back(Clause);
3724 if (!BinOp)
return Cond;
3726 if (BinOp->getOpcode() != BO_LOr)
return Cond;
3729 Expr *LHS = BinOp->getLHS();
3731 if (!InnerBinOp)
return Cond;
3733 if (InnerBinOp->getOpcode() != BO_EQ ||
3734 !isa<IntegerLiteral>(InnerBinOp->getRHS()))
3744 if (MacroName ==
"CONCEPT_REQUIRES" || MacroName ==
"CONCEPT_REQUIRES_")
3745 return BinOp->getRHS();
3755class FailedBooleanConditionPrinterHelper :
public PrinterHelper {
3760 bool handledStmt(
Stmt *E, raw_ostream &OS)
override {
3761 const auto *DR = dyn_cast<DeclRefExpr>(E);
3762 if (DR && DR->getQualifier()) {
3765 DR->getQualifier()->print(OS, Policy,
true);
3769 if (
const auto *IV = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3772 OS, IV->getTemplateArgs().asArray(), Policy,
3773 IV->getSpecializedTemplate()->getTemplateParameters());
3786std::pair<Expr *, std::string>
3795 Expr *FailedCond =
nullptr;
3796 for (
Expr *Term : Terms) {
3800 if (isa<CXXBoolLiteralExpr>(TermAsWritten) ||
3801 isa<IntegerLiteral>(TermAsWritten))
3810 if (Term->EvaluateAsBooleanCondition(Succeeded,
Context) &&
3812 FailedCond = TermAsWritten;
3819 std::string Description;
3821 llvm::raw_string_ostream Out(Description);
3824 FailedBooleanConditionPrinterHelper Helper(Policy);
3825 FailedCond->
printPretty(Out, &Helper, Policy, 0,
"\n",
nullptr);
3827 return { FailedCond, Description };
3834 = Name.getUnderlying().getAsDependentTemplateName();
3844 if (Name.getAsAssumedTemplateName() &&
3849 if (!Template || isa<FunctionTemplateDecl>(Template) ||
3850 isa<VarTemplateDecl>(Template) || isa<ConceptDecl>(Template)) {
3853 if (Name.getAsSubstTemplateTemplateParmPack())
3857 Diag(TemplateLoc, diag::err_template_id_not_a_type)
3867 SugaredConverted, CanonicalConverted,
3874 dyn_cast<TypeAliasTemplateDecl>(Template)) {
3896 if (CanonType.
isNull()) {
3902 if (*DeductionInfo &&
3903 (*DeductionInfo)->hasSFINAEDiagnostic() &&
3904 (*DeductionInfo)->peekSFINAEDiagnostic().second.getDiagID() ==
3905 diag::err_typename_nested_not_found_enable_if &&
3906 TemplateArgs[0].getArgument().getKind()
3909 std::string FailedDescription;
3910 std::tie(FailedCond, FailedDescription) =
3916 (*DeductionInfo)->takeSFINAEDiagnostic(OldDiag);
3920 (*DeductionInfo)->addSFINAEDiagnostic(
3922 PDiag(diag::err_typename_nested_not_found_requirement)
3923 << FailedDescription
3931 }
else if (
auto *BTD = dyn_cast<BuiltinTemplateDecl>(Template)) {
3933 TemplateLoc, TemplateArgs);
3934 }
else if (Name.isDependent() ||
3936 TemplateArgs, CanonicalConverted)) {
3945 Name, CanonicalConverted);
3953 if (isa<ClassTemplateDecl>(Template)) {
3956 if (Ctx->isFileContext())
break;
3960 if (!Record)
continue;
3964 if (!isa<ClassTemplatePartialSpecializationDecl>(Record) &&
3965 !Record->getDescribedClassTemplate())
3971 QualType Injected = cast<InjectedClassNameType>(ICNT)
3972 ->getInjectedSpecializationType();
3985 dyn_cast<ClassTemplateDecl>(Template)) {
3988 void *InsertPos =
nullptr;
3990 ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
4022 assert(isa<RecordType>(CanonType) &&
4023 "type of non-dependent specialization is not a RecordType");
4025 llvm_unreachable(
"Unhandled template kind");
4042 auto *ATN = Name.getAsAssumedTemplateName();
4043 assert(ATN &&
"not an assumed template name");
4044 II = ATN->getDeclName().getAsIdentifierInfo();
4060 assert(ATN &&
"not an assumed template name");
4068 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
4069 return std::make_unique<CandidateCallback>(*
this);
4093 bool IsCtorOrDtorName,
bool IsClassName,
4098 if (!IsCtorOrDtorName && !IsClassName && SS.
isSet()) {
4124 TemplateD, TemplateII, TemplateIILoc, LAngleLoc,
4125 TemplateArgsIn, RAngleLoc);
4132 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
4133 if (LookupRD && LookupRD->getIdentifier() == TemplateII) {
4136 ? diag::err_out_of_line_qualified_id_type_names_constructor
4137 : diag::ext_out_of_line_qualified_id_type_names_constructor)
4155 ETK_None, DTN->getQualifier(), DTN->getIdentifier(),
4167 for (
unsigned I = 0, N = SpecTL.
getNumArgs(); I != N; ++I)
4184 for (
unsigned i = 0, e = SpecTL.
getNumArgs(); i != e; ++i)
4224 Keyword, DTN->getQualifier(), DTN->getIdentifier(),
4237 for (
unsigned I = 0, N = SpecTL.
getNumArgs(); I != N; ++I)
4248 Diag(TemplateLoc, diag::err_tag_reference_non_tag)
4250 Diag(TAT->getLocation(), diag::note_declared_at);
4262 assert(
Id &&
"templated class must have an identifier");
4266 Diag(TagLoc, diag::err_use_with_wrong_tag)
4281 for (
unsigned i = 0, e = SpecTL.
getNumArgs(); i != e; ++i)
4315 return TPT && !
Type.hasQualifiers() &&
4324 dyn_cast<NonTypeTemplateParmDecl>(DRE->
getDecl());
4330 dyn_cast_or_null<TemplateTemplateParmDecl>(
4334 llvm_unreachable(
"unexpected kind of template argument");
4339 if (Params->
size() != Args.size())
4342 unsigned Depth = Params->
getDepth();
4344 for (
unsigned I = 0, N = Args.size(); I != N; ++I) {
4363template<
typename PartialSpecDecl>
4365 if (Partial->getDeclContext()->isDependentContext())
4374 auto *Template = Partial->getSpecializedTemplate();
4375 S.
Diag(Partial->getLocation(),
4376 diag::ext_partial_spec_not_more_specialized_than_primary)
4377 << isa<VarTemplateDecl>(Template);
4386 diag::note_partial_spec_not_more_specialized_than_primary)
4393 Partial->getAssociatedConstraints(PartialAC);
4400 const llvm::SmallBitVector &DeducibleParams) {
4401 for (
unsigned I = 0, N = DeducibleParams.size(); I != N; ++I) {
4402 if (!DeducibleParams[I]) {
4415template<
typename PartialSpecDecl>
4417 PartialSpecDecl *Partial) {
4430 auto *TemplateParams = Partial->getTemplateParameters();
4431 llvm::SmallBitVector DeducibleParams(TemplateParams->
size());
4433 TemplateParams->
getDepth(), DeducibleParams);
4435 if (!DeducibleParams.all()) {
4436 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
4437 S.
Diag(Partial->getLocation(), diag::ext_partial_specs_not_deducible)
4438 << isa<VarTemplatePartialSpecializationDecl>(Partial)
4439 << (NumNonDeducible > 1)
4441 Partial->getTemplateArgsAsWritten()->RAngleLoc);
4462 llvm::SmallBitVector DeducibleParams(TemplateParams->
size());
4464 for (
unsigned I = 0; I != TemplateParams->
size(); ++I) {
4466 auto *Param = TemplateParams->
getParam(I);
4468 DeducibleParams[I] =
true;
4471 if (!DeducibleParams.all()) {
4472 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
4473 Diag(TD->
getLocation(), diag::err_deduction_guide_template_not_deducible)
4474 << (NumNonDeducible > 1);
4485 "Variable template specialization is declared with a template id.");
4498 dyn_cast_or_null<VarTemplateDecl>(Name.getAsTemplateDecl());
4501 if (
auto *OTS = Name.getAsOverloadedTemplate())
4502 FnTemplate = *OTS->begin();
4504 FnTemplate = dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl());
4513 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
4522 false, SugaredConverted, CanonicalConverted,
4530 TemplateArgs.
size(),
4531 CanonicalConverted))
4536 if (!Name.isDependent() &&
4538 TemplateArgs, CanonicalConverted)) {
4539 Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
4545 CanonicalConverted) &&
4552 Diag(TemplateNameLoc, diag::err_partial_spec_args_match_primary_template)
4562 void *InsertPos =
nullptr;
4566 PrevDecl =
VarTemplate->findPartialSpecialization(
4567 CanonicalConverted, TemplateParams, InsertPos);
4569 PrevDecl =
VarTemplate->findSpecialization(CanonicalConverted, InsertPos);
4591 cast_or_null<VarTemplatePartialSpecializationDecl>(PrevDecl);
4596 CanonicalConverted, TemplateArgs);
4599 VarTemplate->AddPartialSpecialization(Partial, InsertPos);
4638 Diag(TemplateNameLoc, diag::err_specialization_after_instantiation)
4642 diag::note_instantiation_required_here)
4678struct PartialSpecMatchResult {
4688 assert(Template &&
"A variable template id without template?");
4693 Template, TemplateNameLoc,
4695 SugaredConverted, CanonicalConverted,
4702 TemplateArgs, CanonicalConverted))
4707 void *InsertPos =
nullptr;
4721 CanonicalConverted);
4723 bool AmbiguousPartialSpec =
false;
4738 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
4751 Matched.push_back(PartialSpecMatchResult());
4752 Matched.back().Partial = Partial;
4757 if (Matched.size() >= 1) {
4759 if (Matched.size() == 1) {
4772 PEnd = Matched.end();
4775 PointOfInstantiation) ==
4783 PEnd = Matched.end();
4786 P->Partial, Best->Partial,
4787 PointOfInstantiation) != Best->Partial) {
4788 AmbiguousPartialSpec =
true;
4795 InstantiationPattern = Best->Partial;
4796 InstantiationArgs = Best->Args;
4808 Template, InstantiationPattern, *InstantiationArgs, TemplateArgs,
4809 CanonicalConverted, TemplateNameLoc );
4813 if (AmbiguousPartialSpec) {
4816 Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous)
4821 Diag(
P.Partial->getLocation(), diag::note_partial_spec_match)
4828 dyn_cast<VarTemplatePartialSpecializationDecl>(InstantiationPattern))
4829 Decl->setInstantiationOf(D, InstantiationArgs);
4833 assert(
Decl &&
"No variable template specialization?");
4845 if (
Decl.isInvalid())
4858 nullptr, TemplateArgs);
4863 Diag(Loc, diag::err_template_missing_args)
4866 Diag(TD->getLocation(), diag::note_template_decl_here)
4867 << TD->getTemplateParameters()->getSourceRange();
4878 assert(NamedConcept &&
"A concept template id without a template?");
4882 NamedConcept, ConceptNameInfo.
getLoc(),
4884 false, SugaredConverted, CanonicalConverted,
4890 CanonicalConverted);
4892 bool AreArgsDependent =
4894 *TemplateArgs, CanonicalConverted);
4902 if (!AreArgsDependent &&
4913 TemplateKWLoc, ConceptNameInfo, FoundDecl, NamedConcept,
4915 AreArgsDependent ?
nullptr : &Satisfaction);
4934 assert(!R.
isAmbiguous() &&
"ambiguous lookup when building templateid");
4938 if (!TemplateArgs && !isa<FunctionTemplateDecl>(TD)) {
4948 TemplateKWLoc, TemplateArgs);
4968 RequiresADL, TemplateArgs,
4981 assert(TemplateArgs || TemplateKWLoc.
isValid());
4988 bool MemberOfUnknownSpecialization;
4991 false, MemberOfUnknownSpecialization,
5004 auto DiagnoseTypeTemplateDecl = [&](
TemplateDecl *Temp,
5005 bool isTypeAliasTemplateDecl) {
5006 Diag(NameInfo.
getLoc(), diag::err_template_kw_refers_to_type_template)
5008 << isTypeAliasTemplateDecl;
5014 return DiagnoseTypeTemplateDecl(Temp,
false);
5017 return DiagnoseTypeTemplateDecl(Temp,
true);
5041 bool EnteringContext,
5043 bool AllowInjectedClassName) {
5044 if (TemplateKWLoc.
isValid() && S && !S->getTemplateParamParent())
5047 diag::warn_cxx98_compat_template_outside_of_template :
5048 diag::ext_template_outside_of_template)
5058 else if (ObjectType)
5077 bool MemberOfUnknownSpecialization;
5079 ObjectType, EnteringContext,
Result,
5080 MemberOfUnknownSpecialization);
5083 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
5084 if (!AllowInjectedClassName && SS.
isNotEmpty() && LookupRD &&
5086 Name.Identifier && LookupRD->getIdentifier() == Name.Identifier) {
5096 Diag(Name.getBeginLoc(),
5097 diag::ext_out_of_line_qualified_id_type_names_constructor)
5105 if (!MemberOfUnknownSpecialization) {