40#include "llvm/ADT/BitVector.h"
41#include "llvm/ADT/SmallBitVector.h"
42#include "llvm/ADT/SmallString.h"
43#include "llvm/ADT/StringExtras.h"
55 return SourceRange(Ps[0]->getTemplateLoc(), Ps[N-1]->getRAngleLoc());
63 for (
Scope *TempParamScope = S->getTemplateParamParent(); TempParamScope;
64 TempParamScope = TempParamScope->getParent()->getTemplateParamParent()) {
69 auto ParamsAtDepth = [&](
unsigned D) { Depth = std::max(Depth,
D + 1); };
74 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(FSI)) {
75 if (!LSI->TemplateParams.empty()) {
76 ParamsAtDepth(LSI->AutoTemplateParameterDepth);
79 if (LSI->GLTemplateParameterList) {
80 ParamsAtDepth(LSI->GLTemplateParameterList->getDepth());
90 if (!Info.TemplateParams.empty()) {
91 ParamsAtDepth(Info.AutoTemplateParameterDepth);
106 bool AllowFunctionTemplates,
107 bool AllowDependent) {
108 D =
D->getUnderlyingDecl();
110 if (isa<TemplateDecl>(
D)) {
111 if (!AllowFunctionTemplates && isa<FunctionTemplateDecl>(
D))
117 if (
const auto *
Record = dyn_cast<CXXRecordDecl>(
D)) {
129 if (
Record->isInjectedClassName()) {
131 if (
Record->getDescribedClassTemplate())
132 return Record->getDescribedClassTemplate();
134 if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(
Record))
135 return Spec->getSpecializedTemplate();
144 if (AllowDependent && isa<UnresolvedUsingValueDecl>(
D))
151 bool AllowFunctionTemplates,
152 bool AllowDependent) {
163 bool AllowFunctionTemplates,
165 bool AllowNonTemplateFunctions) {
169 if (AllowNonTemplateFunctions &&
170 isa<FunctionDecl>((*I)->getUnderlyingDecl()))
179 bool hasTemplateKeyword,
182 bool EnteringContext,
184 bool &MemberOfUnknownSpecialization,
185 bool Disambiguation) {
189 MemberOfUnknownSpecialization =
false;
191 switch (Name.getKind()) {
198 Name.OperatorFunctionId.Operator);
238 bool AnyFunctionTemplates =
false;
241 if (isa<FunctionTemplateDecl>(FoundTemplate))
242 AnyFunctionTemplates =
true;
245 FoundUsingShadow = dyn_cast<UsingShadowDecl>(FoundD);
253 if (!
D && !AnyFunctionTemplates) {
254 R.suppressDiagnostics();
271 unsigned ResultCount = R.
end() - R.
begin();
272 if (!
D && ResultCount > 1) {
283 assert(
D &&
"unambiguous result is not a template name");
286 if (isa<UnresolvedUsingValueDecl>(
D)) {
288 MemberOfUnknownSpecialization =
true;
295 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
302 if (isa<FunctionTemplateDecl>(TD)) {
308 assert(isa<ClassTemplateDecl>(TD) || isa<TemplateTemplateParmDecl>(TD) ||
309 isa<TypeAliasTemplateDecl>(TD) || isa<VarTemplateDecl>(TD) ||
310 isa<BuiltinTemplateDecl>(TD) || isa<ConceptDecl>(TD));
333 if (R.
empty())
return false;
370 Diag(IILoc, diag::err_template_kw_missing)
380 QualType ObjectType,
bool EnteringContext,
383 bool AllowTypoCorrection) {
390 Found.setTemplateNameLookup(
true);
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;
453 IsDependent |=
Found.wasNotFoundInCurrentInstantiation();
469 if (!ObjectType.
isNull()) {
473 AllowFunctionTemplatesInLookup =
false;
474 ObjectTypeSearchedInScope =
true;
477 IsDependent |=
Found.wasNotFoundInCurrentInstantiation();
480 if (
Found.isAmbiguous())
497 if (AllFunctions || (
Found.empty() && !IsDependent)) {
501 *ATK = (
Found.empty() &&
Found.getLookupName().isIdentifier())
509 if (
Found.empty() && !IsDependent && AllowTypoCorrection) {
517 FilterCCC.WantExpressionKeywords =
false;
518 FilterCCC.WantRemainingKeywords =
false;
519 FilterCCC.WantCXXNamedCasts =
true;
523 if (
auto *ND = Corrected.getFoundDecl())
526 if (
Found.isAmbiguous()) {
528 }
else if (!
Found.empty()) {
529 Found.setLookupName(Corrected.getCorrection());
531 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
532 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
533 Name.getAsString() == CorrectedStr;
535 << Name << LookupCtx << DroppedSpecifier
545 Found.empty() ? nullptr :
Found.getRepresentativeDecl();
549 Found.setNotFoundInCurrentInstantiation();
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)
562 <<
Found.getLookupName();
569 if (S && !ObjectType.
isNull() && !ObjectTypeSearchedInScope &&
586 if (FoundOuter.
empty()) {
596 }
else if (!
Found.isSuppressingAmbiguousDiagnostics()) {
600 if (!
Found.isSingleResult() ||
604 diag::ext_nested_name_member_ref_lookup_ambiguous)
605 <<
Found.getLookupName()
607 Diag(
Found.getRepresentativeDecl()->getLocation(),
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);
728 bool isAddressOfOperand,
744 nullptr, NameInfo, TemplateArgs);
767 bool InstantiatedFromMember,
772 assert(isa<TagDecl>(Instantiation) || isa<FunctionDecl>(Instantiation) ||
773 isa<VarDecl>(Instantiation));
775 bool IsEntityBeingDefined =
false;
776 if (
const TagDecl *TD = dyn_cast_or_null<TagDecl>(PatternDef))
777 IsEntityBeingDefined = TD->isBeingDefined();
779 if (PatternDef && !IsEntityBeingDefined) {
794 if (!Complain || (PatternDef && PatternDef->
isInvalidDecl()))
798 if (
TagDecl *TD = dyn_cast<TagDecl>(Instantiation))
801 Diag(PointOfInstantiation,
802 diag::err_template_instantiate_within_definition)
808 }
else if (InstantiatedFromMember) {
809 if (isa<FunctionDecl>(Instantiation)) {
810 Diag(PointOfInstantiation,
811 diag::err_explicit_instantiation_undefined_member)
816 assert(isa<TagDecl>(Instantiation) &&
"Must be a TagDecl!");
817 Diag(PointOfInstantiation,
818 diag::err_implicit_instantiate_member_undefined)
823 if (isa<FunctionDecl>(Instantiation)) {
824 Diag(PointOfInstantiation,
825 diag::err_explicit_instantiation_undefined_func_template)
828 }
else if (isa<TagDecl>(Instantiation)) {
829 Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)
834 assert(isa<VarDecl>(Instantiation) &&
"Must be a VarDecl!");
835 if (isa<VarTemplateSpecializationDecl>(Instantiation)) {
836 Diag(PointOfInstantiation,
837 diag::err_explicit_instantiation_undefined_var_template)
841 Diag(PointOfInstantiation,
842 diag::err_explicit_instantiation_undefined_member)
859 bool SupportedForCompatibility) {
872 ? diag::ext_template_param_shadow
873 : (SupportedForCompatibility ? diag::ext_compat_template_param_shadow
874 : diag::err_template_param_shadow);
875 const auto *ND = cast<NamedDecl>(PrevDecl);
876 Diag(
Loc, DiagId) << ND->getDeclName();
881 if (
TemplateDecl *Temp = dyn_cast_or_null<TemplateDecl>(
D)) {
882 D = Temp->getTemplatedDecl();
891 "Only template template arguments can be pack expansions here");
892 assert(
getAsTemplate().get().containsUnexpandedParameterPack() &&
893 "Template template argument pack expansion without packs");
895 Result.EllipsisLoc = EllipsisLoc;
930 llvm_unreachable(
"Unhandled parsed template argument");
935 for (
unsigned I = 0,
Last = TemplateArgsIn.size(); I !=
Last; ++I)
945 RedeclarationKind::ForVisibleRedeclaration);
955 assert(TInfo &&
"template argument with no location");
963 EllipsisLoc = PET.getEllipsisLoc();
964 TL = PET.getPatternLoc();
969 SS.
Adopt(ET.getQualifierLoc());
970 TL = ET.getNamedTypeLoc();
974 TemplateName Name = DTST.getTypePtr()->getTemplateName();
976 DTST.getTemplateNameLoc());
997 unsigned Depth,
unsigned Position,
1000 bool HasTypeConstraint) {
1001 assert(S->isTemplateParamScope() &&
1002 "Template type parameter not in template parameter scope!");
1004 bool IsParameterPack = EllipsisLoc.
isValid();
1007 KeyLoc, ParamNameLoc, Depth, Position,
1008 ParamName,
Typename, IsParameterPack,
1014 LSI->LocalPacks.push_back(Param);
1027 if (DefaultArg && IsParameterPack) {
1028 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1029 DefaultArg =
nullptr;
1037 assert(DefaultTInfo &&
"expected source information for type");
1065 return TemplateArgs;
1078 diag::err_type_constraint_non_type_concept);
1087 if (!WereArgsSpecified &&
1090 diag::err_type_constraint_missing_arguments)
1109 bool AllowUnexpandedPack) {
1126 if (EllipsisLoc.
isInvalid() && !AllowUnexpandedPack) {
1135 ConceptName, CD, USD ? cast<NamedDecl>(USD) : CD,
1137 ConstrainedParameter, EllipsisLoc);
1140template <
typename ArgumentLocAppender>
1155 Appender(ConstraintArgs);
1164 FoundDecl ? FoundDecl : NamedConcept, NamedConcept,
1167 return ImmediatelyDeclaredConstraint;
1183 ImmediatelyDeclaredConstraint.
get(), BO_LAnd,
1184 EllipsisLoc,
nullptr,
1200 *TemplateArgs) :
nullptr;
1205 *
this,
NS, NameInfo, NamedConcept, FoundDecl,
1208 ParamAsArgument, ConstrainedParameter->
getLocation(),
1211 for (const auto &ArgLoc : TemplateArgs->arguments())
1212 ConstraintArgs.addArgument(ArgLoc);
1215 if (ImmediatelyDeclaredConstraint.
isInvalid())
1225 ImmediatelyDeclaredConstraint.
get());
1236 diag::err_unsupported_placeholder_constraint)
1255 for (unsigned I = 0, C = TL.getNumArgs(); I != C; ++I)
1256 ConstraintArgs.addArgument(TL.getArgLoc(I));
1259 if (ImmediatelyDeclaredConstraint.
isInvalid() ||
1260 !ImmediatelyDeclaredConstraint.
isUsable())
1264 ImmediatelyDeclaredConstraint.
get());
1294 Diag(
Loc, diag::err_template_nontype_parm_rvalue_ref) <<
T;
1304 Diag(
Loc, diag::err_template_nontype_parm_bad_type) <<
T;
1312 Diag(
Loc, diag::err_template_nontype_parm_not_structural) <<
T;
1319 for (
const FieldDecl *FD : RD->fields()) {
1321 Diag(FD->getLocation(), diag::note_not_structural_non_public) <<
T << 0;
1324 if (FD->isMutable()) {
1325 Diag(FD->getLocation(), diag::note_not_structural_mutable_field) <<
T;
1328 if (FD->getType()->isRValueReferenceType()) {
1329 Diag(FD->getLocation(), diag::note_not_structural_rvalue_ref_field)
1336 for (
const auto &BaseSpec : RD->bases()) {
1337 if (BaseSpec.getAccessSpecifier() !=
AS_public) {
1338 Diag(BaseSpec.getBaseTypeLoc(), diag::note_not_structural_non_public)
1349 for (
const FieldDecl *FD : RD->fields()) {
1352 SubLoc = FD->getLocation();
1360 for (
const auto &BaseSpec : RD->bases()) {
1363 SubLoc = BaseSpec.getBaseTypeLoc();
1371 assert(Kind != -1 &&
"couldn't find reason why type is not structural");
1372 Diag(SubLoc, diag::note_not_structural_subobject)
1373 <<
T << Kind << SubType;
1386 Diag(
Loc, diag::err_variably_modified_nontype_template_param)
1410 return T.getUnqualifiedType();
1428 return T.getUnqualifiedType();
1439 Diag(
Loc, diag::err_template_nontype_parm_bad_structural_type) <<
T;
1443 Diag(
Loc, diag::warn_cxx17_compat_template_nontype_parm_type) <<
T;
1444 return T.getUnqualifiedType();
1455 auto CheckValidDeclSpecifiers = [
this, &
D] {
1469 Diag(
Loc, diag::err_invalid_decl_specifier_in_nontype_parm)
1506 CheckValidDeclSpecifiers();
1509 if (isa<AutoType>(
T))
1510 Diag(
D.getIdentifierLoc(),
1511 diag::warn_cxx14_compat_template_nontype_parm_auto_type)
1514 assert(S->isTemplateParamScope() &&
1515 "Non-type template parameter not in template parameter scope!");
1527 bool IsParameterPack =
D.hasEllipsis();
1530 D.getIdentifierLoc(), Depth, Position, ParamName,
T, IsParameterPack,
1535 if (TL.isConstrained())
1544 LSI->LocalPacks.push_back(Param);
1558 if (
Default && IsParameterPack) {
1559 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1582 assert(S->isTemplateParamScope() &&
1583 "Template template parameter not in template parameter scope!");
1586 bool IsParameterPack = EllipsisLoc.
isValid();
1589 NameLoc.
isInvalid() ? TmpLoc : NameLoc, Depth, Position, IsParameterPack,
1595 LSI->LocalPacks.push_back(Param);
1606 if (Params->
size() == 0) {
1615 if (IsParameterPack && !
Default.isInvalid()) {
1616 Diag(EqualLoc, diag::err_template_param_pack_default_arg);
1631 Diag(DefaultArg.
getLocation(), diag::err_template_arg_not_valid_template)
1649class ConstraintRefersToContainingTemplateChecker
1650 :
public TreeTransform<ConstraintRefersToContainingTemplateChecker> {
1651 bool Result =
false;
1653 unsigned TemplateDepth = 0;
1657 void CheckIfContainingRecord(
const CXXRecordDecl *CheckingRD) {
1663 DC && !DC->isFileContext(); DC = DC->getParent())
1664 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
1665 if (CheckingRD == RD->getMostRecentDecl())
1670 assert(
D->getDepth() <= TemplateDepth &&
1671 "Nothing should reference a value below the actual template depth, "
1672 "depth is likely wrong");
1673 if (
D->getDepth() != TemplateDepth)
1678 TransformType(
D->getType());
1684 ConstraintRefersToContainingTemplateChecker(
Sema &SemaRef,
1686 unsigned TemplateDepth)
1687 : inherited(SemaRef),
Friend(
Friend), TemplateDepth(TemplateDepth) {}
1688 bool getResult()
const {
return Result; }
1694 using inherited::TransformTemplateTypeParmType;
1698 "Nothing should reference a value below the actual template depth, "
1699 "depth is likely wrong");
1702 return inherited::TransformTemplateTypeParmType(
1714 if (
auto *TD = dyn_cast<TypedefNameDecl>(
D))
1715 TransformType(TD->getUnderlyingType());
1716 else if (
auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(
D))
1717 CheckNonTypeTemplateParmDecl(NTTPD);
1718 else if (
auto *VD = dyn_cast<ValueDecl>(
D))
1719 TransformType(VD->getType());
1720 else if (
auto *TD = dyn_cast<TemplateDecl>(
D))
1721 TransformTemplateParameterList(TD->getTemplateParameters());
1722 else if (
auto *RD = dyn_cast<CXXRecordDecl>(
D))
1723 CheckIfContainingRecord(RD);
1724 else if (isa<NamedDecl>(
D)) {
1727 llvm_unreachable(
"Don't know how to handle this declaration type yet");
1735 const Expr *Constraint) {
1736 assert(
Friend->getFriendObjectKind() &&
"Only works on a friend");
1737 ConstraintRefersToContainingTemplateChecker Checker(*
this,
Friend,
1739 Checker.TransformExpr(
const_cast<Expr *
>(Constraint));
1740 return Checker.getResult();
1750 Expr *RequiresClause) {
1752 Diag(ExportLoc, diag::warn_template_export_unsupported);
1758 Context, TemplateLoc, LAngleLoc,
1759 llvm::ArrayRef(Params.data(), Params.size()), RAngleLoc, RequiresClause);
1794 return cast<TemplateDecl>(
D)->getTemplateParameters();
1804 assert(TemplateParams && TemplateParams->
size() > 0 &&
1805 "No template parameters");
1807 "Can only declare or define class templates");
1816 "can't build template of enumerated type");
1820 Diag(KWLoc, diag::err_template_unnamed_class);
1835 if (!SemanticContext) {
1840 ? diag::warn_template_qualified_friend_ignored
1841 : diag::err_template_qualified_declarator_no_match)
1884 PrevDecl = (*
Previous.begin())->getUnderlyingDecl();
1896 dyn_cast_or_null<ClassTemplateDecl>(PrevDecl);
1901 if (!PrevClassTemplate && isa_and_nonnull<CXXRecordDecl>(PrevDecl) &&
1902 cast<CXXRecordDecl>(PrevDecl)->isInjectedClassName()) {
1905 = cast<CXXRecordDecl>(PrevDecl)->getDescribedClassTemplate();
1906 if (!PrevClassTemplate && isa<ClassTemplateSpecializationDecl>(PrevDecl)) {
1908 = cast<ClassTemplateSpecializationDecl>(PrevDecl)
1909 ->getSpecializedTemplate();
1932 PrevDecl = PrevClassTemplate =
nullptr;
1933 SemanticContext = OutermostContext;
1947 PrevDecl = (*
Previous.begin())->getUnderlyingDecl();
1951 SemanticContext, S, SS.
isValid()))
1952 PrevDecl = PrevClassTemplate =
nullptr;
1954 if (
auto *Shadow = dyn_cast_or_null<UsingShadowDecl>(
1955 PrevDecl ?
Previous.getRepresentativeDecl() :
nullptr)) {
1957 !(PrevClassTemplate &&
1960 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
1961 Diag(Shadow->getTargetDecl()->getLocation(),
1962 diag::note_using_decl_target);
1963 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) << 0;
1965 PrevDecl = PrevClassTemplate =
nullptr;
1969 if (PrevClassTemplate) {
1978 TemplateParams, PrevClassTemplate,
1991 Diag(KWLoc, diag::err_use_with_wrong_tag)
2007 auto *Tmpl = cast<CXXRecordDecl>(Hidden)->getDescribedClassTemplate();
2008 assert(Tmpl &&
"original definition of a class template is not a "
2013 Diag(NameLoc, diag::err_redefinition) << Name;
2014 Diag(Def->getLocation(), diag::note_previous_definition);
2021 }
else if (PrevDecl) {
2027 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
2041 (SS.
isSet() && SemanticContext && SemanticContext->
isRecord() &&
2054 ? diag::err_friend_decl_does_not_match
2055 : diag::err_member_decl_does_not_match)
2056 << Name << SemanticContext <<
true << SS.
getRange();
2066 bool ShouldAddRedecl =
2071 PrevClassTemplate && ShouldAddRedecl ?
2075 if (NumOuterTemplateParamLists > 0)
2078 llvm::ArrayRef(OuterTemplateParamLists, NumOuterTemplateParamLists));
2092 if (ShouldAddRedecl)
2097 if (ModulePrivateLoc.
isValid())
2108 if (PrevClassTemplate &&
2127 if (PrevClassTemplate)
2163 if (PrevClassTemplate)
2204 diag::warn_cxx98_compat_template_parameter_default_in_function_template
2205 : diag::ext_template_parameter_default_in_function_template)
2214 S.
Diag(ParamLoc, diag::err_template_parameter_default_template_member)
2223 S.
Diag(ParamLoc, diag::err_template_parameter_default_friend_template)
2232 llvm_unreachable(
"Invalid TemplateParamListContext!");
2245 for (
unsigned I = 0, N = Params->
size(); I != N; ++I) {
2250 if (TC->hasExplicitTemplateArgs())
2251 for (
auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
2259 if (!NTTP->isParameterPack() &&
2261 NTTP->getTypeSourceInfo(),
2269 = dyn_cast<TemplateTemplateParmDecl>(
P))
2289 bool SawDefaultArgument =
false;
2295 OldParam = OldParams->
begin();
2297 bool RemoveDefaultArguments =
false;
2299 NewParamEnd = NewParams->
end();
2300 NewParam != NewParamEnd; ++NewParam) {
2303 bool RedundantDefaultArg =
false;
2306 bool InconsistentDefaultArg =
false;
2308 std::string PrevModuleName;
2314 bool MissingDefaultArg =
false;
2317 bool SawParameterPack =
false;
2320 = dyn_cast<TemplateTypeParmDecl>(*NewParam)) {
2322 if (NewTypeParm->hasDefaultArgument() &&
2324 *
this, TPC, NewTypeParm->getLocation(),
2325 NewTypeParm->getDefaultArgument().getSourceRange()))
2326 NewTypeParm->removeDefaultArgument();
2330 = OldParams? cast<TemplateTypeParmDecl>(*OldParam) :
nullptr;
2331 if (NewTypeParm->isParameterPack()) {
2332 assert(!NewTypeParm->hasDefaultArgument() &&
2333 "Parameter packs can't have a default argument!");
2334 SawParameterPack =
true;
2336 NewTypeParm->hasDefaultArgument() &&
2339 NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
2340 SawDefaultArgument =
true;
2343 RedundantDefaultArg =
true;
2344 else if (!
getASTContext().isSameDefaultTemplateArgument(OldTypeParm,
2346 InconsistentDefaultArg =
true;
2350 PreviousDefaultArgLoc = NewDefaultLoc;
2354 NewTypeParm->setInheritedDefaultArgument(
Context, OldTypeParm);
2356 }
else if (NewTypeParm->hasDefaultArgument()) {
2357 SawDefaultArgument =
true;
2358 PreviousDefaultArgLoc = NewTypeParm->getDefaultArgumentLoc();
2359 }
else if (SawDefaultArgument)
2360 MissingDefaultArg =
true;
2362 = dyn_cast<NonTypeTemplateParmDecl>(*NewParam)) {
2364 if (!NewNonTypeParm->isParameterPack() &&
2366 NewNonTypeParm->getTypeSourceInfo(),
2373 if (NewNonTypeParm->hasDefaultArgument() &&
2375 *
this, TPC, NewNonTypeParm->getLocation(),
2376 NewNonTypeParm->getDefaultArgument().getSourceRange())) {
2377 NewNonTypeParm->removeDefaultArgument();
2382 = OldParams? cast<NonTypeTemplateParmDecl>(*OldParam) :
nullptr;
2383 if (NewNonTypeParm->isParameterPack()) {
2384 assert(!NewNonTypeParm->hasDefaultArgument() &&
2385 "Parameter packs can't have a default argument!");
2386 if (!NewNonTypeParm->isPackExpansion())
2387 SawParameterPack =
true;
2389 NewNonTypeParm->hasDefaultArgument() &&
2392 NewDefaultLoc = NewNonTypeParm->getDefaultArgumentLoc();
2393 SawDefaultArgument =
true;
2395 RedundantDefaultArg =
true;
2397 OldNonTypeParm, NewNonTypeParm)) {
2398 InconsistentDefaultArg =
true;
2402 PreviousDefaultArgLoc = NewDefaultLoc;
2406 NewNonTypeParm->setInheritedDefaultArgument(
Context, OldNonTypeParm);
2408 }
else if (NewNonTypeParm->hasDefaultArgument()) {
2409 SawDefaultArgument =
true;
2410 PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc();
2411 }
else if (SawDefaultArgument)
2412 MissingDefaultArg =
true;
2415 = cast<TemplateTemplateParmDecl>(*NewParam);
2432 = OldParams? cast<TemplateTemplateParmDecl>(*OldParam) :
nullptr;
2435 "Parameter packs can't have a default argument!");
2437 SawParameterPack =
true;
2438 }
else if (OldTemplateParm &&
2444 SawDefaultArgument =
true;
2446 RedundantDefaultArg =
true;
2448 OldTemplateParm, NewTemplateParm)) {
2449 InconsistentDefaultArg =
true;
2453 PreviousDefaultArgLoc = NewDefaultLoc;
2458 PreviousDefaultArgLoc
2461 SawDefaultArgument =
true;
2462 PreviousDefaultArgLoc
2464 }
else if (SawDefaultArgument)
2465 MissingDefaultArg =
true;
2471 if (SawParameterPack && (NewParam + 1) != NewParamEnd &&
2474 Diag((*NewParam)->getLocation(),
2475 diag::err_template_param_pack_must_be_last_template_parameter);
2492 if (RedundantDefaultArg) {
2493 Diag(NewDefaultLoc, diag::err_template_param_default_arg_redefinition);
2494 Diag(OldDefaultLoc, diag::note_template_param_prev_default_arg);
2496 }
else if (InconsistentDefaultArg) {
2500 diag::err_template_param_default_arg_inconsistent_redefinition);
2502 diag::note_template_param_prev_default_arg_in_other_module)
2505 }
else if (MissingDefaultArg &&
2513 Diag((*NewParam)->getLocation(),
2514 diag::err_template_param_default_arg_missing);
2515 Diag(PreviousDefaultArgLoc, diag::note_template_param_prev_default_arg);
2517 RemoveDefaultArguments =
true;
2528 if (RemoveDefaultArguments) {
2530 NewParamEnd = NewParams->
end();
2531 NewParam != NewParamEnd; ++NewParam) {
2533 TTP->removeDefaultArgument();
2535 = dyn_cast<NonTypeTemplateParmDecl>(*NewParam))
2536 NTTP->removeDefaultArgument();
2538 cast<TemplateTemplateParmDecl>(*NewParam)->removeDefaultArgument();
2558 bool IgnoreNonTypeDependent;
2563 DependencyChecker(
unsigned Depth,
bool IgnoreNonTypeDependent)
2564 : Depth(Depth), IgnoreNonTypeDependent(IgnoreNonTypeDependent),
2568 : IgnoreNonTypeDependent(IgnoreNonTypeDependent), Match(
false) {
2571 Depth = PD->getDepth();
2573 dyn_cast<NonTypeTemplateParmDecl>(ND)) {
2574 Depth = PD->getDepth();
2576 Depth = cast<TemplateTemplateParmDecl>(ND)->getDepth();
2581 if (ParmDepth >= Depth) {
2589 bool TraverseStmt(
Stmt *S, DataRecursionQueue *Q =
nullptr) {
2594 if (
auto *
E = dyn_cast_or_null<Expr>(S))
2597 return super::TraverseStmt(S, Q);
2600 bool TraverseTypeLoc(
TypeLoc TL) {
2601 if (IgnoreNonTypeDependent && !TL.
isNull() &&
2604 return super::TraverseTypeLoc(TL);
2613 return IgnoreNonTypeDependent || !Matches(
T->getDepth());
2619 if (Matches(PD->getDepth()))
2621 return super::TraverseTemplateName(N);
2626 dyn_cast<NonTypeTemplateParmDecl>(
E->getDecl()))
2629 return super::VisitDeclRefExpr(
E);
2633 return TraverseType(
T->getReplacementType());
2638 return TraverseTemplateArgument(
T->getArgumentPack());
2642 return TraverseType(
T->getInjectedSpecializationType());
2651 if (!Params->
size())
2654 DependencyChecker Checker(Params,
false);
2655 Checker.TraverseType(
T);
2656 return Checker.Match;
2666 if (
const Type *CurType = NNS->getAsType()) {
2682 bool &IsMemberSpecialization,
bool &
Invalid,
bool SuppressDiagnostic) {
2683 IsMemberSpecialization =
false;
2704 while (!
T.isNull()) {
2705 NestedTypes.push_back(
T);
2711 = dyn_cast<ClassTemplateSpecializationDecl>(
Record)) {
2712 if (!isa<ClassTemplatePartialSpecializationDecl>(Spec) &&
2714 ExplicitSpecLoc = Spec->getLocation();
2717 }
else if (
Record->getTemplateSpecializationKind()
2719 ExplicitSpecLoc =
Record->getLocation();
2732 if (
TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
2733 if (
TypeDecl *
Parent = dyn_cast<TypeDecl>(Template->getDeclContext()))
2778 std::reverse(NestedTypes.begin(), NestedTypes.end());
2786 bool SawNonEmptyTemplateParameterList =
false;
2789 if (SawNonEmptyTemplateParameterList) {
2790 if (!SuppressDiagnostic)
2791 Diag(DeclLoc, diag::err_specialize_member_of_template)
2792 << !Recovery <<
Range;
2794 IsMemberSpecialization =
false;
2803 if (CheckExplicitSpecialization(
Range,
true))
2808 if (!ParamLists.empty())
2809 ExpectedTemplateLoc = ParamLists[0]->getTemplateLoc();
2811 ExpectedTemplateLoc = DeclStartLoc;
2813 if (!SuppressDiagnostic)
2814 Diag(DeclLoc, diag::err_template_spec_needs_header)
2821 for (
unsigned TypeIdx = 0, NumTypes = NestedTypes.size(); TypeIdx != NumTypes;
2823 T = NestedTypes[TypeIdx];
2826 bool NeedEmptyTemplateHeader =
false;
2829 bool NeedNonemptyTemplateHeader =
false;
2842 = dyn_cast<ClassTemplatePartialSpecializationDecl>(
Record)) {
2843 ExpectedTemplateParams = Partial->getTemplateParameters();
2844 NeedNonemptyTemplateHeader =
true;
2845 }
else if (
Record->isDependentType()) {
2846 if (
Record->getDescribedClassTemplate()) {
2847 ExpectedTemplateParams =
Record->getDescribedClassTemplate()
2848 ->getTemplateParameters();
2849 NeedNonemptyTemplateHeader =
true;
2852 = dyn_cast<ClassTemplateSpecializationDecl>(
Record)) {
2858 NeedEmptyTemplateHeader =
true;
2861 }
else if (
Record->getTemplateSpecializationKind()) {
2862 if (
Record->getTemplateSpecializationKind()
2864 TypeIdx == NumTypes - 1)
2865 IsMemberSpecialization =
true;
2871 if (
TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
2872 ExpectedTemplateParams = Template->getTemplateParameters();
2873 NeedNonemptyTemplateHeader =
true;
2878 NeedNonemptyTemplateHeader =
false;
2888 if (
ParamIdx < ParamLists.size()) {
2889 if (ParamLists[
ParamIdx]->size() == 0) {
2890 if (CheckExplicitSpecialization(ParamLists[
ParamIdx]->getSourceRange(),
2894 SawNonEmptyTemplateParameterList =
true;
2897 if (NeedEmptyTemplateHeader) {
2900 if (TypeIdx == NumTypes - 1)
2901 IsMemberSpecialization =
true;
2903 if (
ParamIdx < ParamLists.size()) {
2904 if (ParamLists[
ParamIdx]->size() > 0) {
2906 if (!SuppressDiagnostic)
2908 diag::err_template_param_list_matches_nontemplate)
2911 ParamLists[
ParamIdx]->getRAngleLoc())
2923 if (DiagnoseMissingExplicitSpecialization(
2930 if (NeedNonemptyTemplateHeader) {
2936 if (
ParamIdx < ParamLists.size() &&
2938 ExpectedTemplateParams =
nullptr;
2943 if (
ParamIdx < ParamLists.size()) {
2945 if (ExpectedTemplateParams &&
2947 ExpectedTemplateParams,
2960 if (!SuppressDiagnostic)
2961 Diag(DeclLoc, diag::err_template_spec_needs_template_parameters)
2972 if (
ParamIdx >= ParamLists.size()) {
2973 if (TemplateId && !IsFriend) {
2989 if (
ParamIdx < ParamLists.size() - 1) {
2990 bool HasAnyExplicitSpecHeader =
false;
2991 bool AllExplicitSpecHeaders =
true;
2992 for (
unsigned I =
ParamIdx,
E = ParamLists.size() - 1; I !=
E; ++I) {
2993 if (ParamLists[I]->size() == 0)
2994 HasAnyExplicitSpecHeader =
true;
2996 AllExplicitSpecHeaders =
false;
2999 if (!SuppressDiagnostic)
3001 AllExplicitSpecHeaders ? diag::ext_template_spec_extra_headers
3002 : diag::err_template_spec_extra_headers)
3004 ParamLists[ParamLists.size() - 2]->getRAngleLoc());
3009 if (ExplicitSpecLoc.
isValid() && HasAnyExplicitSpecHeader &&
3010 !SuppressDiagnostic)
3011 Diag(ExplicitSpecLoc,
3012 diag::note_explicit_template_spec_does_not_need_header)
3013 << NestedTypes.back();
3018 if (!AllExplicitSpecHeaders)
3029 if (ParamLists.back()->size() == 0 &&
3030 CheckExplicitSpecialization(ParamLists[
ParamIdx]->getSourceRange(),
3036 return ParamLists.back();
3040 if (
TemplateDecl *Template = Name.getAsTemplateDecl()) {
3041 Diag(Template->getLocation(), diag::note_template_declared_here)
3042 << (isa<FunctionTemplateDecl>(Template)
3044 : isa<ClassTemplateDecl>(Template)
3046 : isa<VarTemplateDecl>(Template)
3048 : isa<TypeAliasTemplateDecl>(Template) ? 3 : 4)
3049 << Template->getDeclName();
3057 Diag((*I)->getLocation(), diag::note_template_declared_here)
3058 << 0 << (*I)->getDeclName();
3076 QualType OrigType = Converted[1].getAsType();
3080 SemaRef.
Diag(TemplateArgs[1].getLocation(),
3081 diag::err_integer_sequence_integral_element_type);
3096 OrigType, TemplateArgs[1].getLocation())));
3098 if (llvm::APSInt NumArgs = NumArgsArg.
getAsIntegral(); NumArgs >= 0) {
3100 for (llvm::APSInt I(NumArgs.getBitWidth(), NumArgs.isUnsigned());
3104 TA, OrigType, TemplateArgs[2].getLocation()));
3109 SemaRef.
Diag(TemplateArgs[2].getLocation(),
3110 diag::err_integer_sequence_negative_length);
3117 TemplateLoc, SyntheticTemplateArgs);
3124 assert(Converted.size() == 2 &&
3125 "__type_pack_element should be given an index and a parameter pack");
3133 assert(Index >= 0 &&
"the index used with __type_pack_element should be of "
3134 "type std::size_t, and hence be non-negative");
3136 if (Index >= Ts.pack_size()) {
3137 SemaRef.
Diag(TemplateArgs[0].getLocation(),
3138 diag::err_type_pack_element_out_of_bounds);
3143 int64_t N = Index.getExtValue();
3144 return Ts.getPackAsArray()[N].getAsType();
3146 llvm_unreachable(
"unexpected BuiltinTemplateDecl!");
3165 if (BinOp->getOpcode() == BO_LAnd) {
3172 Terms.push_back(Clause);
3181 if (!BinOp)
return Cond;
3183 if (BinOp->getOpcode() != BO_LOr)
return Cond;
3186 Expr *LHS = BinOp->getLHS();
3188 if (!InnerBinOp)
return Cond;
3190 if (InnerBinOp->getOpcode() != BO_EQ ||
3191 !isa<IntegerLiteral>(InnerBinOp->getRHS()))
3201 if (MacroName ==
"CONCEPT_REQUIRES" || MacroName ==
"CONCEPT_REQUIRES_")
3202 return BinOp->getRHS();
3212class FailedBooleanConditionPrinterHelper :
public PrinterHelper {
3217 bool handledStmt(
Stmt *
E, raw_ostream &OS)
override {
3218 const auto *DR = dyn_cast<DeclRefExpr>(
E);
3219 if (DR && DR->getQualifier()) {
3222 DR->getQualifier()->print(OS, Policy,
true);
3226 if (
const auto *IV = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3229 OS, IV->getTemplateArgs().asArray(), Policy,
3230 IV->getSpecializedTemplate()->getTemplateParameters());
3243std::pair<Expr *, std::string>
3252 Expr *FailedCond =
nullptr;
3253 for (
Expr *Term : Terms) {
3257 if (isa<CXXBoolLiteralExpr>(TermAsWritten) ||
3258 isa<IntegerLiteral>(TermAsWritten))
3267 if (Term->EvaluateAsBooleanCondition(Succeeded,
Context) &&
3269 FailedCond = TermAsWritten;
3276 std::string Description;
3278 llvm::raw_string_ostream Out(Description);
3281 FailedBooleanConditionPrinterHelper Helper(Policy);
3282 FailedCond->
printPretty(Out, &Helper, Policy, 0,
"\n",
nullptr);
3284 return { FailedCond, Description };
3291 = Name.getUnderlying().getAsDependentTemplateName();
3301 if (Name.getAsAssumedTemplateName() &&
3306 if (!Template || isa<FunctionTemplateDecl>(Template) ||
3307 isa<VarTemplateDecl>(Template) || isa<ConceptDecl>(Template)) {
3310 if (Name.getAsSubstTemplateTemplateParmPack())
3314 Diag(TemplateLoc, diag::err_template_id_not_a_type)
3324 SugaredConverted, CanonicalConverted,
3331 dyn_cast<TypeAliasTemplateDecl>(Template)) {
3346 Template, SugaredConverted,
3347 !
getLangOpts().RetainSubstTemplateTypeParmTypeAstNodes);
3363 std::optional<ContextRAII> SavedContext;
3365 SavedContext.emplace(*
this,
AliasTemplate->getDeclContext());
3370 if (CanonType.
isNull()) {
3376 if (*DeductionInfo &&
3377 (*DeductionInfo)->hasSFINAEDiagnostic() &&
3378 (*DeductionInfo)->peekSFINAEDiagnostic().second.getDiagID() ==
3379 diag::err_typename_nested_not_found_enable_if &&
3380 TemplateArgs[0].getArgument().getKind()
3383 std::string FailedDescription;
3384 std::tie(FailedCond, FailedDescription) =
3390 (*DeductionInfo)->takeSFINAEDiagnostic(OldDiag);
3394 (*DeductionInfo)->addSFINAEDiagnostic(
3396 PDiag(diag::err_typename_nested_not_found_requirement)
3397 << FailedDescription
3405 }
else if (
auto *BTD = dyn_cast<BuiltinTemplateDecl>(Template)) {
3407 TemplateLoc, TemplateArgs);
3408 }
else if (Name.isDependent() ||
3410 TemplateArgs, CanonicalConverted)) {
3419 Name, CanonicalConverted);
3427 if (isa<ClassTemplateDecl>(Template)) {
3430 if (Ctx->isFileContext())
break;
3438 if (!isa<ClassTemplatePartialSpecializationDecl>(
Record) &&
3439 !
Record->getDescribedClassTemplate())
3445 QualType Injected = cast<InjectedClassNameType>(ICNT)
3446 ->getInjectedSpecializationType();
3459 dyn_cast<ClassTemplateDecl>(Template)) {
3462 void *InsertPos =
nullptr;
3464 ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
3496 assert(isa<RecordType>(CanonType) &&
3497 "type of non-dependent specialization is not a RecordType");
3499 llvm_unreachable(
"Unhandled template kind");
3516 auto *ATN = Name.getAsAssumedTemplateName();
3517 assert(ATN &&
"not an assumed template name");
3518 II = ATN->getDeclName().getAsIdentifierInfo();
3534 assert(ATN &&
"not an assumed template name");
3542 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
3543 return std::make_unique<CandidateCallback>(*
this);
3567 bool IsCtorOrDtorName,
bool IsClassName,
3572 if (!IsCtorOrDtorName && !IsClassName && SS.
isSet()) {
3598 TemplateD, TemplateII, TemplateIILoc, LAngleLoc,
3599 TemplateArgsIn, RAngleLoc);
3606 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
3607 if (LookupRD && LookupRD->getIdentifier() == TemplateII) {
3610 ? diag::err_out_of_line_qualified_id_type_names_constructor
3611 : diag::ext_out_of_line_qualified_id_type_names_constructor)
3641 for (
unsigned I = 0, N = SpecTL.
getNumArgs(); I != N; ++I)
3658 for (
unsigned i = 0, e = SpecTL.
getNumArgs(); i != e; ++i)
3699 Keyword, DTN->getQualifier(), DTN->getIdentifier(),
3712 for (
unsigned I = 0, N = SpecTL.
getNumArgs(); I != N; ++I)
3723 Diag(TemplateLoc, diag::err_tag_reference_non_tag)
3725 Diag(TAT->getLocation(), diag::note_declared_at);
3737 assert(
Id &&
"templated class must have an identifier");
3741 Diag(TagLoc, diag::err_use_with_wrong_tag)
3756 for (
unsigned i = 0, e = SpecTL.
getNumArgs(); i != e; ++i)
3791 return TPT && !
Type.hasQualifiers() &&
3800 dyn_cast<NonTypeTemplateParmDecl>(DRE->
getDecl());
3806 dyn_cast_or_null<TemplateTemplateParmDecl>(
3810 llvm_unreachable(
"unexpected kind of template argument");
3815 if (Params->
size() != Args.size())
3818 unsigned Depth = Params->
getDepth();
3820 for (
unsigned I = 0, N = Args.size(); I != N; ++I) {
3839template<
typename PartialSpecDecl>
3841 if (Partial->getDeclContext()->isDependentContext())
3850 auto *Template = Partial->getSpecializedTemplate();
3851 S.
Diag(Partial->getLocation(),
3852 diag::ext_partial_spec_not_more_specialized_than_primary)
3853 << isa<VarTemplateDecl>(Template);
3862 diag::note_partial_spec_not_more_specialized_than_primary)
3868 Template->getAssociatedConstraints(TemplateAC);
3869 Partial->getAssociatedConstraints(PartialAC);
3876 const llvm::SmallBitVector &DeducibleParams) {
3877 for (
unsigned I = 0, N = DeducibleParams.size(); I != N; ++I) {
3878 if (!DeducibleParams[I]) {
3891template<
typename PartialSpecDecl>
3893 PartialSpecDecl *Partial) {
3906 auto *TemplateParams = Partial->getTemplateParameters();
3907 llvm::SmallBitVector DeducibleParams(TemplateParams->size());
3909 TemplateParams->getDepth(), DeducibleParams);
3911 if (!DeducibleParams.all()) {
3912 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
3913 S.
Diag(Partial->getLocation(), diag::ext_partial_specs_not_deducible)
3914 << isa<VarTemplatePartialSpecializationDecl>(Partial)
3915 << (NumNonDeducible > 1)
3917 Partial->getTemplateArgsAsWritten()->RAngleLoc);
3938 llvm::SmallBitVector DeducibleParams(TemplateParams->size());
3940 for (
unsigned I = 0; I != TemplateParams->size(); ++I) {
3942 auto *Param = TemplateParams->getParam(I);
3944 DeducibleParams[I] =
true;
3947 if (!DeducibleParams.all()) {
3948 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
3949 Diag(TD->
getLocation(), diag::err_deduction_guide_template_not_deducible)
3950 << (NumNonDeducible > 1);
3961 "Variable template specialization is declared with a template id.");
3974 dyn_cast_or_null<VarTemplateDecl>(Name.getAsTemplateDecl());
3977 if (
auto *OTS = Name.getAsOverloadedTemplate())
3978 FnTemplate = *OTS->begin();
3980 FnTemplate = dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl());
3982 return Diag(
D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method)
3984 return Diag(
D.getIdentifierLoc(), diag::err_var_spec_no_template)
3989 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
4000 false, SugaredConverted, CanonicalConverted,
4008 TemplateArgs.
size(),
4009 CanonicalConverted))
4014 if (!Name.isDependent() &&
4016 TemplateArgs, CanonicalConverted)) {
4017 Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
4023 CanonicalConverted) &&
4030 Diag(TemplateNameLoc, diag::err_partial_spec_args_match_primary_template)
4040 void *InsertPos =
nullptr;
4044 PrevDecl =
VarTemplate->findPartialSpecialization(
4045 CanonicalConverted, TemplateParams, InsertPos);
4047 PrevDecl =
VarTemplate->findSpecialization(CanonicalConverted, InsertPos);
4069 cast_or_null<VarTemplatePartialSpecializationDecl>(PrevDecl);
4074 CanonicalConverted);
4078 VarTemplate->AddPartialSpecialization(Partial, InsertPos);
4117 Diag(TemplateNameLoc, diag::err_specialization_after_instantiation)
4121 diag::note_instantiation_required_here)
4151struct PartialSpecMatchResult {
4161 assert(Template &&
"A variable template id without template?");
4166 Template, TemplateNameLoc,
4168 SugaredConverted, CanonicalConverted,
4175 TemplateArgs, CanonicalConverted))
4180 void *InsertPos =
nullptr;
4194 bool AmbiguousPartialSpec =
false;
4209 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
4223 Matched.push_back(PartialSpecMatchResult());
4224 Matched.back().Partial = Partial;
4229 if (Matched.size() >= 1) {
4231 if (Matched.size() == 1) {
4244 PEnd = Matched.end();
4247 PointOfInstantiation) ==
4255 PEnd = Matched.end();
4258 P->Partial, Best->Partial,
4259 PointOfInstantiation) != Best->Partial) {
4260 AmbiguousPartialSpec =
true;
4267 InstantiationPattern = Best->Partial;
4268 PartialSpecArgs = Best->Args;
4280 Template, InstantiationPattern, PartialSpecArgs, TemplateArgs,
4281 CanonicalConverted, TemplateNameLoc );
4285 if (AmbiguousPartialSpec) {
4288 Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous)
4293 Diag(
P.Partial->getLocation(), diag::note_partial_spec_match)
4300 dyn_cast<VarTemplatePartialSpecializationDecl>(InstantiationPattern))
4301 Decl->setInstantiationOf(
D, PartialSpecArgs);
4305 assert(
Decl &&
"No variable template specialization?");
4316 if (
Decl.isInvalid())
4333 Diag(
Loc, diag::err_template_missing_args)
4341 bool TemplateKeyword,
4356 assert(NamedConcept &&
"A concept template id without a template?");
4360 NamedConcept, ConceptNameInfo.
getLoc(),
4362 false, SugaredConverted, CanonicalConverted,
4370 CanonicalConverted);
4372 bool AreArgsDependent =
4374 *TemplateArgs, CanonicalConverted);
4382 if (!AreArgsDependent &&
4392 TemplateKWLoc, ConceptNameInfo, FoundDecl, NamedConcept,
4395 Context, CL, CSD, AreArgsDependent ?
nullptr : &Satisfaction);
4414 assert(!R.
isAmbiguous() &&
"ambiguous lookup when building templateid");
4418 if (!TemplateArgs && !isa<FunctionTemplateDecl>(TD)) {
4424 bool KnownDependent =
false;
4433 KnownDependent =
true;
4448 R.
begin(), R.
end(), KnownDependent,
4465 assert(TemplateArgs || TemplateKWLoc.
isValid());
4469 false, TemplateKWLoc))
4498 bool EnteringContext,
4500 bool AllowInjectedClassName) {
4501 if (TemplateKWLoc.
isValid() && S && !S->getTemplateParamParent())
4504 diag::warn_cxx98_compat_template_outside_of_template :
4505 diag::ext_template_outside_of_template)
4515 else if (ObjectType)
4534 bool MemberOfUnknownSpecialization;
4536 ObjectType, EnteringContext,
Result,
4537 MemberOfUnknownSpecialization);
4540 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
4541 if (!AllowInjectedClassName && SS.
isNotEmpty() && LookupRD &&
4543 Name.Identifier && LookupRD->getIdentifier() == Name.Identifier) {
4553 Diag(Name.getBeginLoc(),
4554 diag::ext_out_of_line_qualified_id_type_names_constructor)
4562 if (!MemberOfUnknownSpecialization) {
4579 Diag(Name.getBeginLoc(), diag::err_no_member)
4582 Diag(Name.getBeginLoc(), diag::err_undeclared_use)
4590 switch (Name.getKind()) {
4598 Qualifier, Name.OperatorFunctionId.Operator));
4612 Diag(Name.getBeginLoc(),
4613 diag::err_template_kw_refers_to_dependent_non_template)
4615 << TemplateKWLoc.
isValid() << TemplateKWLoc;
4652 dyn_cast<DependentScopeDeclRefExpr>(Arg.
getAsExpr())) {
4653 SS.
Adopt(ArgExpr->getQualifierLoc());
4654 NameInfo = ArgExpr->getNameInfo();
4656 dyn_cast<CXXDependentScopeMemberExpr>(Arg.
getAsExpr())) {
4657 if (ArgExpr->isImplicitAccess()) {
4658 SS.
Adopt(ArgExpr->getQualifierLoc());
4659 NameInfo = ArgExpr->getMemberNameInfo();
4668 Result.wasNotFoundInCurrentInstantiation()) {
4669 assert(SS.
getScopeRep() &&
"dependent scope expr must has a scope!");
4673 ? diag::ext_ms_template_type_arg_missing_typename
4674 : diag::err_template_arg_must_be_type_suggest)
4706 SugaredConverted.push_back(Arg);
4707 CanonicalConverted.push_back(Arg);
4713 Diag(SR.
getBegin(), diag::err_template_arg_must_be_type) << SR;
4735 CanonicalConverted.push_back(
4784 for (
unsigned i = 0, e = Param->
getDepth(); i != e; ++i)
4787 bool ForLambdaCallOperator =
false;
4788 if (
const auto *Rec = dyn_cast<CXXRecordDecl>(Template->
getDeclContext()))
4789 ForLambdaCallOperator = Rec->isLambda();
4791 !ForLambdaCallOperator);
4839 for (
unsigned i = 0, e = Param->
getDepth(); i != e; ++i)
4846 TemplateArgLists, Output);
4882 SugaredConverted,
SourceRange(TemplateLoc, RAngleLoc));
4889 for (
unsigned i = 0, e = Param->
getDepth(); i != e; ++i)
4914 HasDefaultArg =
false;
4920 HasDefaultArg =
true;
4923 TypeParm, SugaredConverted,
4924 CanonicalConverted, Output))
4930 = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
4934 HasDefaultArg =
true;
4937 NonTypeParm, SugaredConverted,
4938 CanonicalConverted, Output))
4944 = cast<TemplateTemplateParmDecl>(Param);
4948 HasDefaultArg =
true;
4951 *
this, Template, TemplateLoc, RAngleLoc, TempTempParm, SugaredConverted,
4952 CanonicalConverted, QualifierLoc);