39#include "llvm/ADT/SmallBitVector.h"
40#include "llvm/ADT/StringExtras.h"
51 return SourceRange(Ps[0]->getTemplateLoc(), Ps[N-1]->getRAngleLoc());
59 for (
Scope *TempParamScope = S->getTemplateParamParent(); TempParamScope;
60 TempParamScope = TempParamScope->getParent()->getTemplateParamParent()) {
65 auto ParamsAtDepth = [&](
unsigned D) { Depth = std::max(Depth,
D + 1); };
70 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(FSI)) {
71 if (!LSI->TemplateParams.empty()) {
72 ParamsAtDepth(LSI->AutoTemplateParameterDepth);
75 if (LSI->GLTemplateParameterList) {
76 ParamsAtDepth(LSI->GLTemplateParameterList->getDepth());
86 if (!Info.TemplateParams.empty()) {
87 ParamsAtDepth(Info.AutoTemplateParameterDepth);
102 bool AllowFunctionTemplates,
103 bool AllowDependent) {
104 D =
D->getUnderlyingDecl();
106 if (isa<TemplateDecl>(
D)) {
107 if (!AllowFunctionTemplates && isa<FunctionTemplateDecl>(
D))
113 if (
const auto *
Record = dyn_cast<CXXRecordDecl>(
D)) {
125 if (
Record->isInjectedClassName()) {
127 if (
Record->getDescribedClassTemplate())
128 return Record->getDescribedClassTemplate();
130 if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(
Record))
131 return Spec->getSpecializedTemplate();
140 if (AllowDependent && isa<UnresolvedUsingValueDecl>(
D))
147 bool AllowFunctionTemplates,
148 bool AllowDependent) {
159 bool AllowFunctionTemplates,
161 bool AllowNonTemplateFunctions) {
165 if (AllowNonTemplateFunctions &&
166 isa<FunctionDecl>((*I)->getUnderlyingDecl()))
175 bool hasTemplateKeyword,
178 bool EnteringContext,
180 bool &MemberOfUnknownSpecialization,
181 bool Disambiguation) {
185 MemberOfUnknownSpecialization =
false;
187 switch (Name.getKind()) {
194 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));
329 if (R.
empty())
return false;
366 Diag(IILoc, diag::err_template_kw_missing)
376 QualType ObjectType,
bool EnteringContext,
379 bool AllowTypoCorrection) {
386 Found.setTemplateNameLookup(
true);
390 bool IsDependent =
false;
391 if (!ObjectType.
isNull()) {
394 assert(SS.
isEmpty() &&
"ObjectType and scope specifier cannot coexist");
400 "Caller should have completed object type");
432 bool ObjectTypeSearchedInScope =
false;
433 bool AllowFunctionTemplatesInLookup =
true;
449 IsDependent |=
Found.wasNotFoundInCurrentInstantiation();
465 if (!ObjectType.
isNull()) {
469 AllowFunctionTemplatesInLookup =
false;
470 ObjectTypeSearchedInScope =
true;
473 IsDependent |=
Found.wasNotFoundInCurrentInstantiation();
476 if (
Found.isAmbiguous())
493 if (AllFunctions || (
Found.empty() && !IsDependent)) {
497 *ATK = (
Found.empty() &&
Found.getLookupName().isIdentifier())
505 if (
Found.empty() && !IsDependent && AllowTypoCorrection) {
513 FilterCCC.WantExpressionKeywords =
false;
514 FilterCCC.WantRemainingKeywords =
false;
515 FilterCCC.WantCXXNamedCasts =
true;
519 if (
auto *ND = Corrected.getFoundDecl())
522 if (
Found.isAmbiguous()) {
524 }
else if (!
Found.empty()) {
525 Found.setLookupName(Corrected.getCorrection());
527 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
528 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
529 Name.getAsString() == CorrectedStr;
531 << Name << LookupCtx << DroppedSpecifier
541 Found.empty() ? nullptr :
Found.getRepresentativeDecl();
545 Found.setNotFoundInCurrentInstantiation();
551 if (ExampleLookupResult && RequiredTemplate) {
552 Diag(
Found.getNameLoc(), diag::err_template_kw_refers_to_non_template)
557 diag::note_template_kw_refers_to_non_template)
558 <<
Found.getLookupName();
565 if (S && !ObjectType.
isNull() && !ObjectTypeSearchedInScope &&
582 if (FoundOuter.
empty()) {
592 }
else if (!
Found.isSuppressingAmbiguousDiagnostics()) {
596 if (!
Found.isSingleResult() ||
600 diag::ext_nested_name_member_ref_lookup_ambiguous)
601 <<
Found.getLookupName()
603 Diag(
Found.getRepresentativeDecl()->getLocation(),
604 diag::note_ambig_member_ref_object_type)
607 diag::note_ambig_member_ref_scope);
630 bool MissingTemplateKeyword =
false;
633 if (
auto *DRE = dyn_cast<DeclRefExpr>(
TemplateName.get())) {
634 NameInfo = DRE->getNameInfo();
635 SS.
Adopt(DRE->getQualifierLoc());
637 Found = DRE->getFoundDecl();
638 }
else if (
auto *ME = dyn_cast<MemberExpr>(
TemplateName.get())) {
639 NameInfo = ME->getMemberNameInfo();
640 SS.
Adopt(ME->getQualifierLoc());
642 LookupCtx = ME->getBase()->getType()->getAsCXXRecordDecl();
643 Found = ME->getMemberDecl();
644 }
else if (
auto *DSDRE =
645 dyn_cast<DependentScopeDeclRefExpr>(
TemplateName.get())) {
646 NameInfo = DSDRE->getNameInfo();
647 SS.
Adopt(DSDRE->getQualifierLoc());
648 MissingTemplateKeyword =
true;
649 }
else if (
auto *DSME =
650 dyn_cast<CXXDependentScopeMemberExpr>(
TemplateName.get())) {
651 NameInfo = DSME->getMemberNameInfo();
652 SS.
Adopt(DSME->getQualifierLoc());
653 MissingTemplateKeyword =
true;
655 llvm_unreachable(
"unexpected kind of potential template name");
660 if (MissingTemplateKeyword) {
669 TemplateCandidateFilter(
Sema &S) : S(S) {
670 WantTypeSpecifiers =
false;
671 WantExpressionKeywords =
false;
672 WantRemainingKeywords =
false;
673 WantCXXNamedCasts =
true;
675 bool ValidateCandidate(
const TypoCorrection &Candidate)
override {
681 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
682 return std::make_unique<TemplateCandidateFilter>(*
this);
687 TemplateCandidateFilter CCC(*
this);
690 auto *ND = Corrected.getFoundDecl();
693 if (ND || Corrected.isKeyword()) {
695 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
696 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
697 Name.getAsString() == CorrectedStr;
699 PDiag(diag::err_non_template_in_member_template_id_suggest)
700 << Name << LookupCtx << DroppedSpecifier
704 PDiag(diag::err_non_template_in_template_id_suggest)
709 diag::note_non_template_in_template_id_found);
714 Diag(NameInfo.
getLoc(), diag::err_non_template_in_template_id)
717 Diag(
Found->getLocation(), diag::note_non_template_in_template_id_found);
724 bool isAddressOfOperand,
740 nullptr, NameInfo, TemplateArgs);
763 bool InstantiatedFromMember,
768 assert(isa<TagDecl>(Instantiation) || isa<FunctionDecl>(Instantiation) ||
769 isa<VarDecl>(Instantiation));
771 bool IsEntityBeingDefined =
false;
772 if (
const TagDecl *TD = dyn_cast_or_null<TagDecl>(PatternDef))
773 IsEntityBeingDefined = TD->isBeingDefined();
775 if (PatternDef && !IsEntityBeingDefined) {
790 if (!Complain || (PatternDef && PatternDef->
isInvalidDecl()))
794 if (
TagDecl *TD = dyn_cast<TagDecl>(Instantiation))
797 Diag(PointOfInstantiation,
798 diag::err_template_instantiate_within_definition)
804 }
else if (InstantiatedFromMember) {
805 if (isa<FunctionDecl>(Instantiation)) {
806 Diag(PointOfInstantiation,
807 diag::err_explicit_instantiation_undefined_member)
812 assert(isa<TagDecl>(Instantiation) &&
"Must be a TagDecl!");
813 Diag(PointOfInstantiation,
814 diag::err_implicit_instantiate_member_undefined)
819 if (isa<FunctionDecl>(Instantiation)) {
820 Diag(PointOfInstantiation,
821 diag::err_explicit_instantiation_undefined_func_template)
824 }
else if (isa<TagDecl>(Instantiation)) {
825 Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)
830 assert(isa<VarDecl>(Instantiation) &&
"Must be a VarDecl!");
831 if (isa<VarTemplateSpecializationDecl>(Instantiation)) {
832 Diag(PointOfInstantiation,
833 diag::err_explicit_instantiation_undefined_var_template)
837 Diag(PointOfInstantiation,
838 diag::err_explicit_instantiation_undefined_member)
855 bool SupportedForCompatibility) {
868 ? diag::ext_template_param_shadow
869 : (SupportedForCompatibility ? diag::ext_compat_template_param_shadow
870 : diag::err_template_param_shadow);
871 const auto *ND = cast<NamedDecl>(PrevDecl);
872 Diag(
Loc, DiagId) << ND->getDeclName();
877 if (
TemplateDecl *Temp = dyn_cast_or_null<TemplateDecl>(
D)) {
878 D = Temp->getTemplatedDecl();
887 "Only template template arguments can be pack expansions here");
888 assert(
getAsTemplate().get().containsUnexpandedParameterPack() &&
889 "Template template argument pack expansion without packs");
891 Result.EllipsisLoc = EllipsisLoc;
926 llvm_unreachable(
"Unhandled parsed template argument");
931 for (
unsigned I = 0,
Last = TemplateArgsIn.size(); I !=
Last; ++I)
941 RedeclarationKind::ForVisibleRedeclaration);
951 assert(TInfo &&
"template argument with no location");
959 EllipsisLoc = PET.getEllipsisLoc();
960 TL = PET.getPatternLoc();
965 SS.
Adopt(ET.getQualifierLoc());
966 TL = ET.getNamedTypeLoc();
970 TemplateName Name = DTST.getTypePtr()->getTemplateName();
972 DTST.getTemplateNameLoc());
993 unsigned Depth,
unsigned Position,
996 bool HasTypeConstraint) {
997 assert(S->isTemplateParamScope() &&
998 "Template type parameter not in template parameter scope!");
1000 bool IsParameterPack = EllipsisLoc.
isValid();
1003 KeyLoc, ParamNameLoc, Depth, Position,
1004 ParamName,
Typename, IsParameterPack,
1010 CSI->LocalPacks.push_back(Param);
1023 if (DefaultArg && IsParameterPack) {
1024 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1025 DefaultArg =
nullptr;
1033 assert(DefaultTInfo &&
"expected source information for type");
1061 return TemplateArgs;
1074 diag::err_type_constraint_non_type_concept);
1083 if (!WereArgsSpecified &&
1086 diag::err_type_constraint_missing_arguments)
1105 bool AllowUnexpandedPack) {
1122 if (EllipsisLoc.
isInvalid() && !AllowUnexpandedPack) {
1131 ConceptName, CD, USD ? cast<NamedDecl>(USD) : CD,
1137template <
typename ArgumentLocAppender>
1152 Appender(ConstraintArgs);
1161 FoundDecl ? FoundDecl : NamedConcept, NamedConcept,
1164 return ImmediatelyDeclaredConstraint;
1180 ImmediatelyDeclaredConstraint.
get(), BO_LAnd,
1181 EllipsisLoc,
nullptr,
1198 *TemplateArgs) :
nullptr;
1200 QualType ParamAsArgument = ConstrainedType;
1203 *
this,
NS, NameInfo, NamedConcept, FoundDecl,
1206 ParamAsArgument, ConstrainedParameter->
getLocation(),
1209 for (const auto &ArgLoc : TemplateArgs->arguments())
1210 ConstraintArgs.addArgument(ArgLoc);
1213 if (ImmediatelyDeclaredConstraint.
isInvalid())
1223 ImmediatelyDeclaredConstraint.
get());
1234 diag::err_unsupported_placeholder_constraint)
1253 for (unsigned I = 0, C = TL.getNumArgs(); I != C; ++I)
1254 ConstraintArgs.addArgument(TL.getArgLoc(I));
1257 if (ImmediatelyDeclaredConstraint.
isInvalid() ||
1258 !ImmediatelyDeclaredConstraint.
isUsable())
1262 ImmediatelyDeclaredConstraint.
get());
1292 Diag(
Loc, diag::err_template_nontype_parm_rvalue_ref) <<
T;
1302 Diag(
Loc, diag::err_template_nontype_parm_bad_type) <<
T;
1310 Diag(
Loc, diag::err_template_nontype_parm_not_structural) <<
T;
1317 for (
const FieldDecl *FD : RD->fields()) {
1319 Diag(FD->getLocation(), diag::note_not_structural_non_public) <<
T << 0;
1322 if (FD->isMutable()) {
1323 Diag(FD->getLocation(), diag::note_not_structural_mutable_field) <<
T;
1326 if (FD->getType()->isRValueReferenceType()) {
1327 Diag(FD->getLocation(), diag::note_not_structural_rvalue_ref_field)
1334 for (
const auto &BaseSpec : RD->bases()) {
1335 if (BaseSpec.getAccessSpecifier() !=
AS_public) {
1336 Diag(BaseSpec.getBaseTypeLoc(), diag::note_not_structural_non_public)
1347 for (
const FieldDecl *FD : RD->fields()) {
1350 SubLoc = FD->getLocation();
1358 for (
const auto &BaseSpec : RD->bases()) {
1361 SubLoc = BaseSpec.getBaseTypeLoc();
1369 assert(Kind != -1 &&
"couldn't find reason why type is not structural");
1370 Diag(SubLoc, diag::note_not_structural_subobject)
1371 <<
T << Kind << SubType;
1384 Diag(
Loc, diag::err_variably_modified_nontype_template_param)
1408 return T.getUnqualifiedType();
1426 return T.getUnqualifiedType();
1437 Diag(
Loc, diag::err_template_nontype_parm_bad_structural_type) <<
T;
1441 Diag(
Loc, diag::warn_cxx17_compat_template_nontype_parm_type) <<
T;
1442 return T.getUnqualifiedType();
1453 auto CheckValidDeclSpecifiers = [
this, &
D] {
1467 Diag(
Loc, diag::err_invalid_decl_specifier_in_nontype_parm)
1504 CheckValidDeclSpecifiers();
1507 if (isa<AutoType>(
T))
1508 Diag(
D.getIdentifierLoc(),
1509 diag::warn_cxx14_compat_template_nontype_parm_auto_type)
1512 assert(S->isTemplateParamScope() &&
1513 "Non-type template parameter not in template parameter scope!");
1525 bool IsParameterPack =
D.hasEllipsis();
1528 D.getIdentifierLoc(), Depth, Position, ParamName,
T, IsParameterPack,
1533 if (TL.isConstrained())
1542 CSI->LocalPacks.push_back(Param);
1556 if (
Default && IsParameterPack) {
1557 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1580 assert(S->isTemplateParamScope() &&
1581 "Template template parameter not in template parameter scope!");
1584 bool IsParameterPack = EllipsisLoc.
isValid();
1587 NameLoc.
isInvalid() ? TmpLoc : NameLoc, Depth, Position, IsParameterPack,
1593 LSI->LocalPacks.push_back(Param);
1604 if (Params->
size() == 0) {
1613 if (IsParameterPack && !
Default.isInvalid()) {
1614 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1629 Diag(DefaultArg.
getLocation(), diag::err_template_arg_not_valid_template)
1647class ConstraintRefersToContainingTemplateChecker
1648 :
public TreeTransform<ConstraintRefersToContainingTemplateChecker> {
1649 bool Result =
false;
1651 unsigned TemplateDepth = 0;
1655 void CheckIfContainingRecord(
const CXXRecordDecl *CheckingRD) {
1661 DC && !DC->isFileContext(); DC = DC->getParent())
1662 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
1663 if (CheckingRD == RD->getMostRecentDecl())
1668 if (
D->getDepth() < TemplateDepth)
1673 TransformType(
D->getType());
1679 ConstraintRefersToContainingTemplateChecker(
Sema &SemaRef,
1681 unsigned TemplateDepth)
1682 : inherited(SemaRef),
Friend(
Friend), TemplateDepth(TemplateDepth) {}
1683 bool getResult()
const {
return Result; }
1689 using inherited::TransformTemplateTypeParmType;
1694 return inherited::TransformTemplateTypeParmType(
1706 if (
auto *TD = dyn_cast<TypedefNameDecl>(
D))
1707 TransformType(TD->getUnderlyingType());
1708 else if (
auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(
D))
1709 CheckNonTypeTemplateParmDecl(NTTPD);
1710 else if (
auto *VD = dyn_cast<ValueDecl>(
D))
1711 TransformType(VD->getType());
1712 else if (
auto *TD = dyn_cast<TemplateDecl>(
D))
1713 TransformTemplateParameterList(TD->getTemplateParameters());
1714 else if (
auto *RD = dyn_cast<CXXRecordDecl>(
D))
1715 CheckIfContainingRecord(RD);
1716 else if (isa<NamedDecl>(
D)) {
1719 llvm_unreachable(
"Don't know how to handle this declaration type yet");
1727 const Expr *Constraint) {
1728 assert(
Friend->getFriendObjectKind() &&
"Only works on a friend");
1729 ConstraintRefersToContainingTemplateChecker Checker(*
this,
Friend,
1731 Checker.TransformExpr(
const_cast<Expr *
>(Constraint));
1732 return Checker.getResult();
1742 Expr *RequiresClause) {
1744 Diag(ExportLoc, diag::warn_template_export_unsupported);
1750 Context, TemplateLoc, LAngleLoc,
1751 llvm::ArrayRef(Params.data(), Params.size()), RAngleLoc, RequiresClause);
1786 return cast<TemplateDecl>(
D)->getTemplateParameters();
1796 assert(TemplateParams && TemplateParams->
size() > 0 &&
1797 "No template parameters");
1799 "Can only declare or define class templates");
1808 "can't build template of enumerated type");
1812 Diag(KWLoc, diag::err_template_unnamed_class);
1827 if (!SemanticContext) {
1832 ? diag::warn_template_qualified_friend_ignored
1833 : diag::err_template_qualified_declarator_no_match)
1892 if (S->isTemplateParamScope())
1897 PrevDecl = (*
Previous.begin())->getUnderlyingDecl();
1909 dyn_cast_or_null<ClassTemplateDecl>(PrevDecl);
1914 if (!PrevClassTemplate && isa_and_nonnull<CXXRecordDecl>(PrevDecl) &&
1915 cast<CXXRecordDecl>(PrevDecl)->isInjectedClassName()) {
1918 = cast<CXXRecordDecl>(PrevDecl)->getDescribedClassTemplate();
1919 if (!PrevClassTemplate && isa<ClassTemplateSpecializationDecl>(PrevDecl)) {
1921 = cast<ClassTemplateSpecializationDecl>(PrevDecl)
1922 ->getSpecializedTemplate();
1945 PrevDecl = PrevClassTemplate =
nullptr;
1946 SemanticContext = OutermostContext;
1960 PrevDecl = (*
Previous.begin())->getUnderlyingDecl();
1964 SemanticContext, S, SS.
isValid()))
1965 PrevDecl = PrevClassTemplate =
nullptr;
1967 if (
auto *Shadow = dyn_cast_or_null<UsingShadowDecl>(
1968 PrevDecl ?
Previous.getRepresentativeDecl() :
nullptr)) {
1970 !(PrevClassTemplate &&
1973 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
1974 Diag(Shadow->getTargetDecl()->getLocation(),
1975 diag::note_using_decl_target);
1976 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) << 0;
1978 PrevDecl = PrevClassTemplate =
nullptr;
1982 if (PrevClassTemplate) {
1991 TemplateParams, PrevClassTemplate,
2004 Diag(KWLoc, diag::err_use_with_wrong_tag)
2020 auto *Tmpl = cast<CXXRecordDecl>(Hidden)->getDescribedClassTemplate();
2021 assert(Tmpl &&
"original definition of a class template is not a "
2026 Diag(NameLoc, diag::err_redefinition) << Name;
2027 Diag(Def->getLocation(), diag::note_previous_definition);
2034 }
else if (PrevDecl) {
2040 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
2054 (SS.
isSet() && SemanticContext && SemanticContext->
isRecord() &&
2067 ? 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())
2121 if (PrevClassTemplate &&
2140 if (PrevClassTemplate)
2176 if (PrevClassTemplate)
2217 diag::warn_cxx98_compat_template_parameter_default_in_function_template
2218 : diag::ext_template_parameter_default_in_function_template)
2227 S.
Diag(ParamLoc, diag::err_template_parameter_default_template_member)
2236 S.
Diag(ParamLoc, diag::err_template_parameter_default_friend_template)
2245 llvm_unreachable(
"Invalid TemplateParamListContext!");
2258 for (
unsigned I = 0, N = Params->
size(); I != N; ++I) {
2263 if (TC->hasExplicitTemplateArgs())
2264 for (
auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
2272 if (!NTTP->isParameterPack() &&
2274 NTTP->getTypeSourceInfo(),
2282 = dyn_cast<TemplateTemplateParmDecl>(
P))
2302 bool SawDefaultArgument =
false;
2308 OldParam = OldParams->
begin();
2310 bool RemoveDefaultArguments =
false;
2312 NewParamEnd = NewParams->
end();
2313 NewParam != NewParamEnd; ++NewParam) {
2316 bool RedundantDefaultArg =
false;
2319 bool InconsistentDefaultArg =
false;
2321 std::string PrevModuleName;
2327 bool MissingDefaultArg =
false;
2330 bool SawParameterPack =
false;
2333 = dyn_cast<TemplateTypeParmDecl>(*NewParam)) {
2335 if (NewTypeParm->hasDefaultArgument() &&
2337 *
this, TPC, NewTypeParm->getLocation(),
2338 NewTypeParm->getDefaultArgument().getSourceRange()))
2339 NewTypeParm->removeDefaultArgument();
2343 = OldParams? cast<TemplateTypeParmDecl>(*OldParam) :
nullptr;
2344 if (NewTypeParm->isParameterPack()) {
2345 assert(!NewTypeParm->hasDefaultArgument() &&
2346 "Parameter packs can't have a default argument!");
2347 SawParameterPack =
true;
2349 NewTypeParm->hasDefaultArgument() &&
2352 NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
2353 SawDefaultArgument =
true;
2356 RedundantDefaultArg =
true;
2357 else if (!
getASTContext().isSameDefaultTemplateArgument(OldTypeParm,
2359 InconsistentDefaultArg =
true;
2363 PreviousDefaultArgLoc = NewDefaultLoc;
2367 NewTypeParm->setInheritedDefaultArgument(
Context, OldTypeParm);
2369 }
else if (NewTypeParm->hasDefaultArgument()) {
2370 SawDefaultArgument =
true;
2371 PreviousDefaultArgLoc = NewTypeParm->getDefaultArgumentLoc();
2372 }
else if (SawDefaultArgument)
2373 MissingDefaultArg =
true;
2375 = dyn_cast<NonTypeTemplateParmDecl>(*NewParam)) {
2377 if (!NewNonTypeParm->isParameterPack() &&
2379 NewNonTypeParm->getTypeSourceInfo(),
2386 if (NewNonTypeParm->hasDefaultArgument() &&
2388 *
this, TPC, NewNonTypeParm->getLocation(),
2389 NewNonTypeParm->getDefaultArgument().getSourceRange())) {
2390 NewNonTypeParm->removeDefaultArgument();
2395 = OldParams? cast<NonTypeTemplateParmDecl>(*OldParam) :
nullptr;
2396 if (NewNonTypeParm->isParameterPack()) {
2397 assert(!NewNonTypeParm->hasDefaultArgument() &&
2398 "Parameter packs can't have a default argument!");
2399 if (!NewNonTypeParm->isPackExpansion())
2400 SawParameterPack =
true;
2402 NewNonTypeParm->hasDefaultArgument() &&
2405 NewDefaultLoc = NewNonTypeParm->getDefaultArgumentLoc();
2406 SawDefaultArgument =
true;
2408 RedundantDefaultArg =
true;
2410 OldNonTypeParm, NewNonTypeParm)) {
2411 InconsistentDefaultArg =
true;
2415 PreviousDefaultArgLoc = NewDefaultLoc;
2419 NewNonTypeParm->setInheritedDefaultArgument(
Context, OldNonTypeParm);
2421 }
else if (NewNonTypeParm->hasDefaultArgument()) {
2422 SawDefaultArgument =
true;
2423 PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc();
2424 }
else if (SawDefaultArgument)
2425 MissingDefaultArg =
true;
2428 = cast<TemplateTemplateParmDecl>(*NewParam);
2445 = OldParams? cast<TemplateTemplateParmDecl>(*OldParam) :
nullptr;
2448 "Parameter packs can't have a default argument!");
2450 SawParameterPack =
true;
2451 }
else if (OldTemplateParm &&
2457 SawDefaultArgument =
true;
2459 RedundantDefaultArg =
true;
2461 OldTemplateParm, NewTemplateParm)) {
2462 InconsistentDefaultArg =
true;
2466 PreviousDefaultArgLoc = NewDefaultLoc;
2471 PreviousDefaultArgLoc
2474 SawDefaultArgument =
true;
2475 PreviousDefaultArgLoc
2477 }
else if (SawDefaultArgument)
2478 MissingDefaultArg =
true;
2484 if (SawParameterPack && (NewParam + 1) != NewParamEnd &&
2487 Diag((*NewParam)->getLocation(),
2488 diag::err_template_param_pack_must_be_last_template_parameter);
2505 if (RedundantDefaultArg) {
2506 Diag(NewDefaultLoc, diag::err_template_param_default_arg_redefinition);
2507 Diag(OldDefaultLoc, diag::note_template_param_prev_default_arg);
2509 }
else if (InconsistentDefaultArg) {
2513 diag::err_template_param_default_arg_inconsistent_redefinition);
2515 diag::note_template_param_prev_default_arg_in_other_module)
2518 }
else if (MissingDefaultArg &&
2526 Diag((*NewParam)->getLocation(),
2527 diag::err_template_param_default_arg_missing);
2528 Diag(PreviousDefaultArgLoc, diag::note_template_param_prev_default_arg);
2530 RemoveDefaultArguments =
true;
2541 if (RemoveDefaultArguments) {
2543 NewParamEnd = NewParams->
end();
2544 NewParam != NewParamEnd; ++NewParam) {
2546 TTP->removeDefaultArgument();
2548 = dyn_cast<NonTypeTemplateParmDecl>(*NewParam))
2549 NTTP->removeDefaultArgument();
2551 cast<TemplateTemplateParmDecl>(*NewParam)->removeDefaultArgument();
2569 bool IgnoreNonTypeDependent;
2574 DependencyChecker(
unsigned Depth,
bool IgnoreNonTypeDependent)
2575 : Depth(Depth), IgnoreNonTypeDependent(IgnoreNonTypeDependent),
2579 : IgnoreNonTypeDependent(IgnoreNonTypeDependent), Match(
false) {
2582 Depth = PD->getDepth();
2584 dyn_cast<NonTypeTemplateParmDecl>(ND)) {
2585 Depth = PD->getDepth();
2587 Depth = cast<TemplateTemplateParmDecl>(ND)->getDepth();
2592 if (ParmDepth >= Depth) {
2600 bool TraverseStmt(
Stmt *S)
override {
2605 if (
auto *
E = dyn_cast_or_null<Expr>(S))
2611 bool TraverseTypeLoc(
TypeLoc TL)
override {
2612 if (IgnoreNonTypeDependent && !TL.
isNull() &&
2624 return IgnoreNonTypeDependent || !Matches(
T->getDepth());
2630 if (Matches(PD->getDepth()))
2637 dyn_cast<NonTypeTemplateParmDecl>(
E->getDecl()))
2640 return DynamicRecursiveASTVisitor::VisitDeclRefExpr(
E);
2644 return TraverseType(
T->getReplacementType());
2647 bool VisitSubstTemplateTypeParmPackType(
2649 return TraverseTemplateArgument(
T->getArgumentPack());
2653 return TraverseType(
T->getInjectedSpecializationType());
2662 if (!Params->
size())
2665 DependencyChecker Checker(Params,
false);
2666 Checker.TraverseType(
T);
2667 return Checker.Match;
2677 if (
const Type *CurType = NNS->getAsType()) {
2693 bool &IsMemberSpecialization,
bool &
Invalid,
bool SuppressDiagnostic) {
2694 IsMemberSpecialization =
false;
2715 while (!
T.isNull()) {
2716 NestedTypes.push_back(
T);
2722 = dyn_cast<ClassTemplateSpecializationDecl>(
Record)) {
2723 if (!isa<ClassTemplatePartialSpecializationDecl>(Spec) &&
2725 ExplicitSpecLoc = Spec->getLocation();
2728 }
else if (
Record->getTemplateSpecializationKind()
2730 ExplicitSpecLoc =
Record->getLocation();
2743 if (
TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
2744 if (
TypeDecl *
Parent = dyn_cast<TypeDecl>(Template->getDeclContext()))
2789 std::reverse(NestedTypes.begin(), NestedTypes.end());
2797 bool SawNonEmptyTemplateParameterList =
false;
2800 if (SawNonEmptyTemplateParameterList) {
2801 if (!SuppressDiagnostic)
2802 Diag(DeclLoc, diag::err_specialize_member_of_template)
2803 << !Recovery <<
Range;
2805 IsMemberSpecialization =
false;
2814 if (CheckExplicitSpecialization(
Range,
true))
2819 if (!ParamLists.empty())
2820 ExpectedTemplateLoc = ParamLists[0]->getTemplateLoc();
2822 ExpectedTemplateLoc = DeclStartLoc;
2824 if (!SuppressDiagnostic)
2825 Diag(DeclLoc, diag::err_template_spec_needs_header)
2832 for (
unsigned TypeIdx = 0, NumTypes = NestedTypes.size(); TypeIdx != NumTypes;
2834 T = NestedTypes[TypeIdx];
2837 bool NeedEmptyTemplateHeader =
false;
2840 bool NeedNonemptyTemplateHeader =
false;
2853 = dyn_cast<ClassTemplatePartialSpecializationDecl>(
Record)) {
2854 ExpectedTemplateParams = Partial->getTemplateParameters();
2855 NeedNonemptyTemplateHeader =
true;
2856 }
else if (
Record->isDependentType()) {
2857 if (
Record->getDescribedClassTemplate()) {
2858 ExpectedTemplateParams =
Record->getDescribedClassTemplate()
2859 ->getTemplateParameters();
2860 NeedNonemptyTemplateHeader =
true;
2863 = dyn_cast<ClassTemplateSpecializationDecl>(
Record)) {
2869 NeedEmptyTemplateHeader =
true;
2872 }
else if (
Record->getTemplateSpecializationKind()) {
2873 if (
Record->getTemplateSpecializationKind()
2875 TypeIdx == NumTypes - 1)
2876 IsMemberSpecialization =
true;
2882 if (
TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
2883 ExpectedTemplateParams = Template->getTemplateParameters();
2884 NeedNonemptyTemplateHeader =
true;
2889 NeedNonemptyTemplateHeader =
false;
2899 if (
ParamIdx < ParamLists.size()) {
2900 if (ParamLists[
ParamIdx]->size() == 0) {
2901 if (CheckExplicitSpecialization(ParamLists[
ParamIdx]->getSourceRange(),
2905 SawNonEmptyTemplateParameterList =
true;
2908 if (NeedEmptyTemplateHeader) {
2911 if (TypeIdx == NumTypes - 1)
2912 IsMemberSpecialization =
true;
2914 if (
ParamIdx < ParamLists.size()) {
2915 if (ParamLists[
ParamIdx]->size() > 0) {
2917 if (!SuppressDiagnostic)
2919 diag::err_template_param_list_matches_nontemplate)
2922 ParamLists[
ParamIdx]->getRAngleLoc())
2934 if (DiagnoseMissingExplicitSpecialization(
2941 if (NeedNonemptyTemplateHeader) {
2947 if (
ParamIdx < ParamLists.size() &&
2949 ExpectedTemplateParams =
nullptr;
2954 if (
ParamIdx < ParamLists.size()) {
2956 if (ExpectedTemplateParams &&
2958 ExpectedTemplateParams,
2971 if (!SuppressDiagnostic)
2972 Diag(DeclLoc, diag::err_template_spec_needs_template_parameters)
2983 if (
ParamIdx >= ParamLists.size()) {
2984 if (TemplateId && !IsFriend) {
3000 if (
ParamIdx < ParamLists.size() - 1) {
3001 bool HasAnyExplicitSpecHeader =
false;
3002 bool AllExplicitSpecHeaders =
true;
3003 for (
unsigned I =
ParamIdx,
E = ParamLists.size() - 1; I !=
E; ++I) {
3004 if (ParamLists[I]->size() == 0)
3005 HasAnyExplicitSpecHeader =
true;
3007 AllExplicitSpecHeaders =
false;
3010 if (!SuppressDiagnostic)
3012 AllExplicitSpecHeaders ? diag::ext_template_spec_extra_headers
3013 : diag::err_template_spec_extra_headers)
3015 ParamLists[ParamLists.size() - 2]->getRAngleLoc());
3020 if (ExplicitSpecLoc.
isValid() && HasAnyExplicitSpecHeader &&
3021 !SuppressDiagnostic)
3022 Diag(ExplicitSpecLoc,
3023 diag::note_explicit_template_spec_does_not_need_header)
3024 << NestedTypes.back();
3029 if (!AllExplicitSpecHeaders)
3040 if (ParamLists.back()->size() == 0 &&
3041 CheckExplicitSpecialization(ParamLists[
ParamIdx]->getSourceRange(),
3047 return ParamLists.back();
3051 if (
TemplateDecl *Template = Name.getAsTemplateDecl()) {
3052 Diag(Template->getLocation(), diag::note_template_declared_here)
3053 << (isa<FunctionTemplateDecl>(Template)
3055 : isa<ClassTemplateDecl>(Template)
3057 : isa<VarTemplateDecl>(Template)
3059 : isa<TypeAliasTemplateDecl>(Template) ? 3 : 4)
3060 << Template->getDeclName();
3068 Diag((*I)->getLocation(), diag::note_template_declared_here)
3069 << 0 << (*I)->getDeclName();
3102 return BaseTemplateInst;
3107 switch (Ts.size()) {
3117 return lookUpCommonType(Ts[0], Ts[0]);
3131 return lookUpCommonType(D1, D2);
3136 auto CheckConditionalOperands = [&](
bool ConstRefQual) ->
QualType {
3175 if (
auto Res = CheckConditionalOperands(
false); !Res.isNull())
3188 return CheckConditionalOperands(
true);
3199 for (
auto T : llvm::drop_begin(Ts)) {
3221 QualType OrigType = Converted[1].getAsType();
3225 SemaRef.
Diag(TemplateArgs[1].getLocation(),
3226 diag::err_integer_sequence_integral_element_type);
3241 OrigType, TemplateArgs[1].getLocation())));
3243 if (llvm::APSInt NumArgs = NumArgsArg.
getAsIntegral(); NumArgs >= 0) {
3245 for (llvm::APSInt I(NumArgs.getBitWidth(), NumArgs.isUnsigned());
3249 TA, OrigType, TemplateArgs[2].getLocation()));
3254 SemaRef.
Diag(TemplateArgs[2].getLocation(),
3255 diag::err_integer_sequence_negative_length);
3262 TemplateLoc, SyntheticTemplateArgs);
3269 assert(Converted.size() == 2 &&
3270 "__type_pack_element should be given an index and a parameter pack");
3278 assert(Index >= 0 &&
"the index used with __type_pack_element should be of "
3279 "type std::size_t, and hence be non-negative");
3281 if (Index >= Ts.pack_size()) {
3282 SemaRef.
Diag(TemplateArgs[0].getLocation(),
3283 diag::err_type_pack_element_out_of_bounds);
3288 int64_t N = Index.getExtValue();
3289 return Ts.getPackAsArray()[N].getAsType();
3293 assert(Converted.size() == 4);
3294 if (llvm::any_of(Converted, [](
auto &
C) {
return C.isDependent(); }))
3298 TemplateName BaseTemplate = Converted[0].getAsTemplate();
3299 TemplateName HasTypeMember = Converted[1].getAsTemplate();
3300 QualType HasNoTypeMember = Converted[2].getAsType();
3307 CT, TemplateArgs[1].getLocation())));
3311 return HasNoTypeMember;
3314 llvm_unreachable(
"unexpected BuiltinTemplateDecl!");
3333 if (BinOp->getOpcode() == BO_LAnd) {
3340 Terms.push_back(Clause);
3349 if (!BinOp)
return Cond;
3351 if (BinOp->getOpcode() != BO_LOr)
return Cond;
3354 Expr *LHS = BinOp->getLHS();
3356 if (!InnerBinOp)
return Cond;
3358 if (InnerBinOp->getOpcode() != BO_EQ ||
3359 !isa<IntegerLiteral>(InnerBinOp->getRHS()))
3369 if (MacroName ==
"CONCEPT_REQUIRES" || MacroName ==
"CONCEPT_REQUIRES_")
3370 return BinOp->getRHS();
3380class FailedBooleanConditionPrinterHelper :
public PrinterHelper {
3385 bool handledStmt(
Stmt *
E, raw_ostream &OS)
override {
3386 const auto *DR = dyn_cast<DeclRefExpr>(
E);
3387 if (DR && DR->getQualifier()) {
3390 DR->getQualifier()->print(OS, Policy,
true);
3394 if (
const auto *IV = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3397 OS, IV->getTemplateArgs().asArray(), Policy,
3398 IV->getSpecializedTemplate()->getTemplateParameters());
3411std::pair<Expr *, std::string>
3420 Expr *FailedCond =
nullptr;
3421 for (
Expr *Term : Terms) {
3425 if (isa<CXXBoolLiteralExpr>(TermAsWritten) ||
3426 isa<IntegerLiteral>(TermAsWritten))
3435 if (Term->EvaluateAsBooleanCondition(Succeeded,
Context) &&
3437 FailedCond = TermAsWritten;
3444 std::string Description;
3446 llvm::raw_string_ostream Out(Description);
3449 FailedBooleanConditionPrinterHelper Helper(Policy);
3450 FailedCond->
printPretty(Out, &Helper, Policy, 0,
"\n",
nullptr);
3452 return { FailedCond, Description };
3459 Name.getUnderlying().getAsDependentTemplateName();
3469 if (Name.getAsAssumedTemplateName() &&
3473 auto [Template, DefaultArgs] = Name.getTemplateDeclAndDefaultArgs();
3475 if (!Template || isa<FunctionTemplateDecl>(Template) ||
3476 isa<VarTemplateDecl>(Template) || isa<ConceptDecl>(Template)) {
3479 if (Name.getAsSubstTemplateTemplateParmPack())
3483 Diag(TemplateLoc, diag::err_template_id_not_a_type)
3493 DefaultArgs,
false, SugaredConverted,
3501 dyn_cast<TypeAliasTemplateDecl>(Template)) {
3516 Template, SugaredConverted,
3517 !
getLangOpts().RetainSubstTemplateTypeParmTypeAstNodes);
3533 std::optional<ContextRAII> SavedContext;
3535 SavedContext.emplace(*
this,
AliasTemplate->getDeclContext());
3540 if (CanonType.
isNull()) {
3546 if (*DeductionInfo &&
3547 (*DeductionInfo)->hasSFINAEDiagnostic() &&
3548 (*DeductionInfo)->peekSFINAEDiagnostic().second.getDiagID() ==
3549 diag::err_typename_nested_not_found_enable_if &&
3550 TemplateArgs[0].getArgument().getKind()
3553 std::string FailedDescription;
3554 std::tie(FailedCond, FailedDescription) =
3560 (*DeductionInfo)->takeSFINAEDiagnostic(OldDiag);
3564 (*DeductionInfo)->addSFINAEDiagnostic(
3566 PDiag(diag::err_typename_nested_not_found_requirement)
3567 << FailedDescription
3575 }
else if (
auto *BTD = dyn_cast<BuiltinTemplateDecl>(Template)) {
3577 TemplateLoc, TemplateArgs);
3578 }
else if (Name.isDependent() ||
3580 TemplateArgs, CanonicalConverted)) {
3589 Name, CanonicalConverted);
3597 if (isa<ClassTemplateDecl>(Template)) {
3600 if (Ctx->isFileContext())
break;
3608 if (!isa<ClassTemplatePartialSpecializationDecl>(
Record) &&
3609 !
Record->getDescribedClassTemplate())
3615 QualType Injected = cast<InjectedClassNameType>(ICNT)
3616 ->getInjectedSpecializationType();
3629 dyn_cast<ClassTemplateDecl>(Template)) {
3632 void *InsertPos =
nullptr;
3634 ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
3666 assert(isa<RecordType>(CanonType) &&
3667 "type of non-dependent specialization is not a RecordType");
3669 llvm_unreachable(
"Unhandled template kind");
3686 auto *ATN = Name.getAsAssumedTemplateName();
3687 assert(ATN &&
"not an assumed template name");
3688 II = ATN->getDeclName().getAsIdentifierInfo();
3704 assert(ATN &&
"not an assumed template name");
3712 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
3713 return std::make_unique<CandidateCallback>(*
this);
3739 bool IsCtorOrDtorName,
bool IsClassName,
3744 if (!IsCtorOrDtorName && !IsClassName && SS.
isSet()) {
3770 TemplateD, TemplateII, TemplateIILoc, LAngleLoc,
3771 TemplateArgsIn, RAngleLoc);
3778 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
3779 if (LookupRD && LookupRD->getIdentifier() == TemplateII) {
3782 ? diag::err_out_of_line_qualified_id_type_names_constructor
3783 : diag::ext_out_of_line_qualified_id_type_names_constructor)
3813 for (
unsigned I = 0, N = SpecTL.
getNumArgs(); I != N; ++I)
3830 for (
unsigned i = 0, e = SpecTL.
getNumArgs(); i != e; ++i)
3871 Keyword, DTN->getQualifier(), DTN->getIdentifier(),
3884 for (
unsigned I = 0, N = SpecTL.
getNumArgs(); I != N; ++I)
3895 Diag(TemplateLoc, diag::err_tag_reference_non_tag)
3897 Diag(TAT->getLocation(), diag::note_declared_at);
3909 assert(
Id &&
"templated class must have an identifier");
3913 Diag(TagLoc, diag::err_use_with_wrong_tag)
3928 for (
unsigned i = 0, e = SpecTL.
getNumArgs(); i != e; ++i)
3963 return TPT && !
Type.hasQualifiers() &&
3972 dyn_cast<NonTypeTemplateParmDecl>(DRE->
getDecl());
3978 dyn_cast_or_null<TemplateTemplateParmDecl>(
3982 llvm_unreachable(
"unexpected kind of template argument");
3987 if (Params->
size() != Args.size())
3990 unsigned Depth = Params->
getDepth();
3992 for (
unsigned I = 0, N = Args.size(); I != N; ++I) {
4011template<
typename PartialSpecDecl>
4013 if (Partial->getDeclContext()->isDependentContext())
4022 auto *Template = Partial->getSpecializedTemplate();
4023 S.
Diag(Partial->getLocation(),
4024 diag::ext_partial_spec_not_more_specialized_than_primary)
4025 << isa<VarTemplateDecl>(Template);
4034 diag::note_partial_spec_not_more_specialized_than_primary)
4040 Template->getAssociatedConstraints(TemplateAC);
4041 Partial->getAssociatedConstraints(PartialAC);
4048 const llvm::SmallBitVector &DeducibleParams) {
4049 for (
unsigned I = 0, N = DeducibleParams.size(); I != N; ++I) {
4050 if (!DeducibleParams[I]) {
4063template<
typename PartialSpecDecl>
4065 PartialSpecDecl *Partial) {
4078 auto *TemplateParams = Partial->getTemplateParameters();
4079 llvm::SmallBitVector DeducibleParams(TemplateParams->size());
4081 TemplateParams->getDepth(), DeducibleParams);
4083 if (!DeducibleParams.all()) {
4084 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
4085 S.
Diag(Partial->getLocation(), diag::ext_partial_specs_not_deducible)
4086 << isa<VarTemplatePartialSpecializationDecl>(Partial)
4087 << (NumNonDeducible > 1)
4089 Partial->getTemplateArgsAsWritten()->RAngleLoc);
4110 llvm::SmallBitVector DeducibleParams(TemplateParams->size());
4112 for (
unsigned I = 0; I != TemplateParams->size(); ++I) {
4114 auto *Param = TemplateParams->getParam(I);
4116 DeducibleParams[I] =
true;
4119 if (!DeducibleParams.all()) {
4120 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
4121 Diag(TD->
getLocation(), diag::err_deduction_guide_template_not_deducible)
4122 << (NumNonDeducible > 1);
4133 "Variable template specialization is declared with a template id.");
4146 dyn_cast_or_null<VarTemplateDecl>(Name.getAsTemplateDecl());
4149 if (
auto *OTS = Name.getAsOverloadedTemplate())
4150 FnTemplate = *OTS->begin();
4152 FnTemplate = dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl());
4154 return Diag(
D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method)
4156 return Diag(
D.getIdentifierLoc(), diag::err_var_spec_no_template)
4160 if (
const auto *DSA =
VarTemplate->getAttr<NoSpecializationsAttr>()) {
4161 auto Message = DSA->getMessage();
4162 Diag(TemplateNameLoc, diag::warn_invalid_specialization)
4164 Diag(DSA->getLoc(), diag::note_marked_here) << DSA;
4168 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
4179 {},
false, SugaredConverted,
4188 TemplateArgs.
size(),
4189 CanonicalConverted))
4194 if (!Name.isDependent() &&
4196 TemplateArgs, CanonicalConverted)) {
4197 Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
4203 CanonicalConverted) &&
4210 Diag(TemplateNameLoc, diag::err_partial_spec_args_match_primary_template)
4220 void *InsertPos =
nullptr;
4224 PrevDecl =
VarTemplate->findPartialSpecialization(
4225 CanonicalConverted, TemplateParams, InsertPos);
4227 PrevDecl =
VarTemplate->findSpecialization(CanonicalConverted, InsertPos);
4249 cast_or_null<VarTemplatePartialSpecializationDecl>(PrevDecl);
4254 CanonicalConverted);
4258 VarTemplate->AddPartialSpecialization(Partial, InsertPos);
4297 Diag(TemplateNameLoc, diag::err_specialization_after_instantiation)
4301 diag::note_instantiation_required_here)
4331struct PartialSpecMatchResult {
4341 assert(Template &&
"A variable template id without template?");
4346 Template, TemplateNameLoc,
4348 {},
false, SugaredConverted, CanonicalConverted,
4355 TemplateArgs, CanonicalConverted))
4360 void *InsertPos =
nullptr;
4374 bool AmbiguousPartialSpec =
false;
4400 !Partial->getMostRecentDecl()->isMemberSpecialization())
4415 Matched.push_back(PartialSpecMatchResult());
4416 Matched.back().Partial = Partial;
4421 if (Matched.size() >= 1) {
4423 if (Matched.size() == 1) {
4436 PEnd = Matched.end();
4439 PointOfInstantiation) ==
4447 PEnd = Matched.end();
4450 P->Partial, Best->Partial,
4451 PointOfInstantiation) != Best->Partial) {
4452 AmbiguousPartialSpec =
true;
4459 InstantiationPattern = Best->Partial;
4460 PartialSpecArgs = Best->Args;
4472 Template, InstantiationPattern, PartialSpecArgs, TemplateArgs,
4473 CanonicalConverted, TemplateNameLoc );
4477 if (AmbiguousPartialSpec) {
4480 Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous)
4485 Diag(
P.Partial->getLocation(), diag::note_partial_spec_match)
4492 dyn_cast<VarTemplatePartialSpecializationDecl>(InstantiationPattern))
4493 Decl->setInstantiationOf(
D, PartialSpecArgs);
4497 assert(
Decl &&
"No variable template specialization?");
4508 if (
Decl.isInvalid())
4525 Diag(
Loc, diag::err_template_missing_args)
4533 bool TemplateKeyword,
4548 assert(NamedConcept &&
"A concept template id without a template?");
4552 NamedConcept, ConceptNameInfo.
getLoc(),
4555 false, SugaredConverted, CanonicalConverted,
4563 CanonicalConverted);
4565 bool AreArgsDependent =
4567 *TemplateArgs, CanonicalConverted);
4575 if (!AreArgsDependent &&
4585 TemplateKWLoc, ConceptNameInfo, FoundDecl, NamedConcept,
4588 Context, CL, CSD, AreArgsDependent ?
nullptr : &Satisfaction);
4607 assert(!R.
isAmbiguous() &&
"ambiguous lookup when building templateid");
4611 if (!TemplateArgs && !isa<FunctionTemplateDecl>(TD)) {
4617 bool KnownDependent =
false;
4626 KnownDependent =
true;
4641 R.
begin(), R.
end(), KnownDependent,
4658 assert(TemplateArgs || TemplateKWLoc.
isValid());
4662 false, TemplateKWLoc))
4691 bool EnteringContext,
4693 bool AllowInjectedClassName) {
4694 if (TemplateKWLoc.
isValid() && S && !S->getTemplateParamParent())
4697 diag::warn_cxx98_compat_template_outside_of_template :
4698 diag::ext_template_outside_of_template)
4708 else if (ObjectType)
4727 bool MemberOfUnknownSpecialization;
4729 ObjectType, EnteringContext,
Result,
4730 MemberOfUnknownSpecialization);
4733 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
4734 if (!AllowInjectedClassName && SS.
isNotEmpty() && LookupRD &&
4736 Name.Identifier && LookupRD->getIdentifier() == Name.Identifier) {
4746 Diag(Name.getBeginLoc(),
4747 diag::ext_out_of_line_qualified_id_type_names_constructor)
4755 if (!MemberOfUnknownSpecialization) {
4772 Diag(Name.getBeginLoc(), diag::err_no_member)
4775 Diag(Name.getBeginLoc(), diag::err_undeclared_use)
4783 switch (Name.getKind()) {
4791 Qualifier, Name.OperatorFunctionId.Operator));
4805 Diag(Name.getBeginLoc(),
4806 diag::err_template_kw_refers_to_dependent_non_template)
4808 << TemplateKWLoc.
isValid() << TemplateKWLoc;
4845 dyn_cast<DependentScopeDeclRefExpr>(Arg.
getAsExpr())) {
4846 SS.
Adopt(ArgExpr->getQualifierLoc());
4847 NameInfo = ArgExpr->getNameInfo();
4849 dyn_cast<CXXDependentScopeMemberExpr>(Arg.
getAsExpr())) {
4850 if (ArgExpr->isImplicitAccess()) {
4851 SS.
Adopt(ArgExpr->getQualifierLoc());
4852 NameInfo = ArgExpr->getMemberNameInfo();
4861 Result.wasNotFoundInCurrentInstantiation()) {
4862 assert(SS.
getScopeRep() &&
"dependent scope expr must has a scope!");
4866 ? diag::ext_ms_template_type_arg_missing_typename
4867 : diag::err_template_arg_must_be_type_suggest)
4899 SugaredConverted.push_back(Arg);
4900 CanonicalConverted.push_back(Arg);
4906 Diag(SR.
getBegin(), diag::err_template_arg_must_be_type) << SR;
4928 CanonicalConverted.push_back(