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

1 //===------- SemaTemplate.cpp - Semantic Analysis for C++ Templates -------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
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); };
75 if (!LSI->TemplateParams.empty()) {
76 ParamsAtDepth(LSI->AutoTemplateParameterDepth);
79 if (LSI->GLTemplateParameterList) {
80 ParamsAtDepth(LSI->GLTemplateParameterList->getDepth());
105 NamedDecl *Sema::getAsTemplateNameDecl(NamedDecl *D,
108 D = D->getUnderlyingDecl();
110 if (isa<TemplateDecl>(D)) {
111 if (!AllowFunctionTemplates && isa<FunctionTemplateDecl>(D))
114 return D;
117 if (const auto *Record = dyn_cast<CXXRecordDecl>(D)) {
119 // Like normal (non-template) classes, class templates have an
120 // injected-class-name (Clause 9). The injected-class-name
121 // can be used with or without a template-argument-list. When
122 // it is used without a template-argument-list, it is
123 // equivalent to the injected-class-name followed by the
124 // template-parameters of the class template enclosed in
125 // <>. When it is used with a template-argument-list, it
129 if (Record->isInjectedClassName()) {
130 Record = cast<CXXRecordDecl>(Record->getDeclContext());
131 if (Record->getDescribedClassTemplate())
132 return Record->getDescribedClassTemplate();
135 return Spec->getSpecializedTemplate();
143 // injected-class-name).
144 if (AllowDependent && isa<UnresolvedUsingValueDecl>(D))
145 return D;
170 isa<FunctionDecl>((*I)->getUnderlyingDecl()))
233 NamedDecl *D = nullptr;
236 // If we got an ambiguity involving a non-function template, treat this
244 D = FoundTemplate;
253 if (!D && !AnyFunctionTemplates) {
260 if (!D)
264 // At this point, we have either picked a single template name declaration D
265 // or we have a non-empty set of results R containing either one template name
271 unsigned ResultCount = R.end() - R.begin();
272 if (!D && ResultCount > 1) {
281 if (!D) {
282 D = getAsTemplateNameDecl(*R.begin());
283 assert(D && "unambiguous result is not a template name");
286 if (isa<UnresolvedUsingValueDecl>(D)) {
287 // We don't yet know whether this is a template-name or not.
292 TemplateDecl *TD = cast<TemplateDecl>(D);
295 assert(!FoundUsingShadow || FoundUsingShadow->getTargetDecl() == TD);
340 // We only treat template-names that name type templates as valid deduction
363 if (!SS || !SS->isSet() || !isDependentScopeSpecifier(*SS) ||
369 NestedNameSpecifier *Qualifier = (NestedNameSpecifier*)SS->getScopeRep();
396 // This nested-name-specifier occurs in a member access expression, e.g.,
397 // x->B::f, and we are looking into the type of the object.
400 IsDependent = !LookupCtx && ObjectType->isDependentType();
401 assert((IsDependent || !ObjectType->isIncompleteType() ||
402 !ObjectType->getAs<TagType>() ||
403 ObjectType->castAs<TagType>()->isBeingDefined()) &&
406 // Template names cannot appear inside an Objective-C class or object type
418 // for lookups into Objective-C class and object types, where the same
420 if (ObjectType->isObjCObjectOrInterfaceType() ||
421 ObjectType->isVectorType()) {
426 // This nested-name-specifier occurs after another nested-name-specifier,
427 // so long into the context associated with the prior nested-name-specifier.
442 // nested-name-specifier.
447 // Clang, we treat a name after a . or -> as a template-name if lookup
448 // finds a non-dependent member or member of the current instantiation that
450 // of the postfix-expression finds a type template. In the latter case, the
458 // In a class member access expression (5.2.5), if the . or -> token is
461 // beginning of a template argument list (14.2) or a less-than operator.
464 // the context of the entire postfix-expression and shall name a class
470 // FIXME: We should filter out all non-type templates here, particularly
487 // unqualified-id followed by a < and name lookup finds either one or more
492 // successfully form a call to an undeclared template-id.
495 return isa<FunctionDecl>(ND->getUnderlyingDecl());
500 // template-id.
553 // If a 'template' keyword was used, a lookup that finds only non-template
560 Diag(ExampleLookupResult->getUnderlyingDecl()->getLocation(),
574 // postfix-expression and [...]
587 // - if the name is not found, the name found in the class of the
592 // - if the name is found in the context of the entire
593 // postfix-expression and does not name a class template, the name
597 // - if the name found is a class template, it must refer to the same
599 // otherwise the program is ill-formed.
601 getAsTemplateNameDecl(Found.getFoundDecl())->getCanonicalDecl() !=
602 OuterTemplate->getCanonicalDecl()) {
607 Diag(Found.getRepresentativeDecl()->getLocation(),
610 Diag(FoundOuter.getFoundDecl()->getLocation(),
638 NameInfo = DRE->getNameInfo();
639 SS.Adopt(DRE->getQualifierLoc());
641 Found = DRE->getFoundDecl();
643 NameInfo = ME->getMemberNameInfo();
644 SS.Adopt(ME->getQualifierLoc());
646 LookupCtx = ME->getBase()->getType()->getAsCXXRecordDecl();
647 Found = ME->getMemberDecl();
650 NameInfo = DSDRE->getNameInfo();
651 SS.Adopt(DSDRE->getQualifierLoc());
655 NameInfo = DSME->getMemberNameInfo();
656 SS.Adopt(DSME->getQualifierLoc());
662 // If this is a dependent-scope lookup, diagnose that the 'template' keyword
712 Diag(Found->getLocation(),
721 Diag(Found->getLocation(), diag::note_non_template_in_template_id_found);
732 // (e.g. a dependent conversion-function-id, or operator= once we support
758 TemplateArgs ? TemplateArgs->getRAngleLoc() : NameInfo.getEndLoc(), {});
777 IsEntityBeingDefined = TD->isBeingDefined();
794 if (!Complain || (PatternDef && PatternDef->isInvalidDecl()))
807 Instantiation->setInvalidDecl();
812 << /*member function*/ 1 << Instantiation->getDeclName()
813 << Instantiation->getDeclContext();
814 Diag(Pattern->getLocation(), diag::note_explicit_instantiation_here);
820 Diag(Pattern->getLocation(), diag::note_member_declared_at);
827 Diag(Pattern->getLocation(), diag::note_explicit_instantiation_here);
839 Instantiation->setInvalidDecl();
843 << /*static data member*/ 2 << Instantiation->getDeclName()
844 << Instantiation->getDeclContext();
845 Diag(Pattern->getLocation(), diag::note_explicit_instantiation_here);
851 // explicit declaration -> explicit definition conversion can't handle
854 Instantiation->setInvalidDecl();
860 assert(PrevDecl->isTemplateParameter() && "Not a template parameter");
863 // The name of a template-parameter shall not be bound to any following.
865 // template-parameter belongs.
869 // true, in which case it is a default-to-error warning.
876 Diag(Loc, DiagId) << ND->getDeclName();
880 TemplateDecl *Sema::AdjustDeclIfTemplate(Decl *&D) {
881 if (TemplateDecl *Temp = dyn_cast_or_null<TemplateDecl>(D)) {
882 D = Temp->getTemplatedDecl();
946 if (PrevDecl && PrevDecl->isTemplateParameter())
960 TypeLoc TL = TInfo->getTypeLoc();
974 TemplateName Name = DTST.getTypePtr()->getTemplateName();
984 // argument is an injected-class-name for a template, it has a dual nature
989 TInfo->getTypeLoc().getBeginLoc());
1001 assert(S->isTemplateParamScope() &&
1010 Param->setAccess(AS_public);
1012 if (Param->isParameterPack())
1014 LSI->LocalPacks.push_back(Param);
1020 S->AddDecl(Param);
1025 // A default template-argument may be specified for any kind of
1026 // template-parameter that is not a template parameter pack.
1046 Param->setInvalidDecl();
1050 Param->setDefaultArgument(
1051 Context, TemplateArgumentLoc(DefaultTInfo->getType(), DefaultTInfo));
1070 TemplateName TN = TypeConstr->Template.get();
1074 // [...] The concept designated by a type-constraint shall be a type
1076 if (!CD->isTypeConcept()) {
1077 Diag(TypeConstr->TemplateNameLoc,
1082 bool WereArgsSpecified = TypeConstr->LAngleLoc.isValid();
1085 CD->getTemplateParameters()->getMinRequiredArguments() > 1) {
1086 Diag(TypeConstr->TemplateNameLoc,
1111 TemplateName TN = TypeConstr->Template.get();
1115 DeclarationNameInfo ConceptName(DeclarationName(TypeConstr->Name),
1116 TypeConstr->TemplateNameLoc);
1119 if (TypeConstr->LAngleLoc.isValid()) {
1133 TypeConstr->LAngleLoc.isValid() ? &TemplateArgs : nullptr,
1155 // [...] This constraint-expression E is called the immediately-declared
1199 QualType ParamAsArgument(ConstrainedParameter->getTypeForDecl(), 0);
1203 TemplateArgs ? TemplateArgs->getLAngleLoc() : SourceLocation(),
1204 TemplateArgs ? TemplateArgs->getRAngleLoc() : SourceLocation(),
1205 ParamAsArgument, ConstrainedParameter->getLocation(),
1208 for (const auto &ArgLoc : TemplateArgs->arguments())
1221 ConstrainedParameter->setTypeConstraint(CL,
1230 if (NewConstrainedParm->getType() != TL.getType() ||
1232 Diag(NewConstrainedParm->getTypeSourceInfo()->getTypeLoc().getBeginLoc(),
1234 << NewConstrainedParm->getTypeSourceInfo()
1235 ->getTypeLoc()
1242 BuildDeclRefExpr(OrigConstrainedParm, OrigConstrainedParm->getType(),
1243 VK_PRValue, OrigConstrainedParm->getLocation());
1250 OrigConstrainedParm->getLocation(),
1260 NewConstrainedParm->setPlaceholderTypeConstraint(
1267 if (TSI->getType()->isUndeducedType()) {
1269 // An id-expression is type-dependent if it contains
1270 // - an identifier associated by name lookup with a non-type
1271 // template-parameter declared with a type that contains a
1276 return CheckNonTypeTemplateParameterType(TSI->getType(), Loc);
1280 if (T->isDependentType())
1286 if (T->isStructuralType())
1290 if (T->isRValueReferenceType()) {
1296 // there's not much more we can say about non-scalar non-class types --
1300 (!T->isScalarType() && !T->isRecordType())) {
1311 // Drill down into the reason why the class is non-structural.
1312 while (const CXXRecordDecl *RD = T->getAsCXXRecordDecl()) {
1313 // All members are required to be public and non-mutable, and can't be of
1316 for (const FieldDecl *FD : RD->fields()) {
1317 if (FD->getAccess() != AS_public) {
1318 Diag(FD->getLocation(), diag::note_not_structural_non_public) << T << 0;
1321 if (FD->isMutable()) {
1322 Diag(FD->getLocation(), diag::note_not_structural_mutable_field) << T;
1325 if (FD->getType()->isRValueReferenceType()) {
1326 Diag(FD->getLocation(), diag::note_not_structural_rvalue_ref_field)
1333 for (const auto &BaseSpec : RD->bases()) {
1344 int Kind = -1;
1346 for (const FieldDecl *FD : RD->fields()) {
1347 QualType T = Context.getBaseElementType(FD->getType());
1348 if (!T->isStructuralType()) {
1349 SubLoc = FD->getLocation();
1356 if (Kind == -1) {
1357 for (const auto &BaseSpec : RD->bases()) {
1359 if (!T->isStructuralType()) {
1368 assert(Kind != -1 && "couldn't find reason why type is not structural");
1372 RD = T->getAsCXXRecordDecl();
1380 // We don't allow variably-modified types as the type of non-type template
1382 if (T->isVariablyModifiedType()) {
1390 // A non-type template-parameter shall have one of the following
1391 // (optionally cv-qualified) types:
1393 // -- integral or enumeration type,
1394 if (T->isIntegralOrEnumerationType() ||
1395 // -- pointer to object or pointer to function,
1396 T->isPointerType() ||
1397 // -- lvalue reference to object or lvalue reference to function,
1398 T->isLValueReferenceType() ||
1399 // -- pointer to member,
1400 T->isMemberPointerType() ||
1401 // -- std::nullptr_t, or
1402 T->isNullPtrType() ||
1403 // -- a type that contains a placeholder type.
1404 T->isUndeducedType()) {
1405 // C++ [temp.param]p5: The top-level cv-qualifiers on the template-parameter
1412 // A non-type template-parameter of type "array of T" or
1415 if (T->isArrayType() || T->isFunctionType())
1419 // assume that it is well-formed. Note that stripping off the
1424 if (T->isDependentType())
1428 // -- a structural type
1444 NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
1449 TypeSourceInfo *TInfo = GetTypeForDeclarator(D);
1451 // Check that we have valid decl-specifiers specified.
1452 auto CheckValidDeclSpecifiers = [this, &D] {
1455 // template-parameter:
1457 // parameter-declaration
1459 // ... A storage class shall not be specified in a template-parameter
1462 // The typedef specifier [...] shall not be used in the decl-specifier-seq
1463 // of a parameter-declaration
1464 const DeclSpec &DS = D.getDeclSpec();
1491 // Function-specifiers can be used only in function declarations.
1505 if (const auto *T = TInfo->getType()->getContainedDeducedType())
1507 Diag(D.getIdentifierLoc(),
1509 << QualType(TInfo->getType()->getContainedAutoType(), 0);
1511 assert(S->isTemplateParamScope() &&
1512 "Non-type template parameter not in template parameter scope!");
1515 QualType T = CheckNonTypeTemplateParameterType(TInfo, D.getIdentifierLoc());
1521 CheckFunctionOrTemplateParamDeclarator(S, D);
1523 const IdentifierInfo *ParamName = D.getIdentifier();
1524 bool IsParameterPack = D.hasEllipsis();
1526 Context, Context.getTranslationUnitDecl(), D.getBeginLoc(),
1527 D.getIdentifierLoc(), Depth, Position, ParamName, T, IsParameterPack,
1529 Param->setAccess(AS_public);
1531 if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
1533 if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
1537 Param->setInvalidDecl();
1539 if (Param->isParameterPack())
1541 LSI->LocalPacks.push_back(Param);
1544 maybeDiagnoseTemplateParameterShadow(*this, S, D.getIdentifierLoc(),
1548 S->AddDecl(Param);
1553 // A default template-argument may be specified for any kind of
1554 // template-parameter that is not a template parameter pack.
1560 // Check the well-formedness of the default template argument, if provided.
1566 Param->setDefaultArgument(
1579 assert(S->isTemplateParamScope() &&
1588 Param->setAccess(AS_public);
1590 if (Param->isParameterPack())
1592 LSI->LocalPacks.push_back(Param);
1599 S->AddDecl(Param);
1603 if (Params->size() == 0) {
1604 Diag(Param->getLocation(), diag::err_template_template_parm_no_parms)
1605 << SourceRange(Params->getLAngleLoc(), Params->getRAngleLoc());
1606 Param->setInvalidDecl();
1610 // A default template-argument may be specified for any kind of
1611 // template-parameter that is not a template parameter pack.
1619 // try to check well-formedness now, because our template template parameter
1639 Param->setDefaultArgument(Context, DefaultArg);
1652 // Check a record-decl that we've seen to see if it is a lexical parent of the
1655 CheckingRD = CheckingRD->getMostRecentDecl();
1656 if (!CheckingRD->isTemplated())
1659 for (const DeclContext *DC = Friend->getLexicalDeclContext();
1660 DC && !DC->isFileContext(); DC = DC->getParent())
1662 if (CheckingRD == RD->getMostRecentDecl())
1666 void CheckNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
1667 assert(D->getDepth() <= TemplateDepth &&
1670 if (D->getDepth() != TemplateDepth)
1675 TransformType(D->getType());
1692 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1694 assert(TL.getDecl()->getDepth() <= TemplateDepth &&
1697 if (TL.getDecl()->getDepth() != TemplateDepth)
1700 TLB, TL,
1704 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
1705 if (!D)
1706 return D;
1711 if (auto *TD = dyn_cast<TypedefNameDecl>(D))
1712 TransformType(TD->getUnderlyingType());
1713 else if (auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(D))
1715 else if (auto *VD = dyn_cast<ValueDecl>(D))
1716 TransformType(VD->getType());
1717 else if (auto *TD = dyn_cast<TemplateDecl>(D))
1718 TransformTemplateParameterList(TD->getTemplateParameters());
1719 else if (auto *RD = dyn_cast<CXXRecordDecl>(D))
1721 else if (isa<NamedDecl>(D)) {
1725 return D;
1733 assert(Friend->getFriendObjectKind() && "Only works on a friend");
1762 T->setQualifierInfo(SS.getWithLocInContext(S.Context));
1771 Decl *D = TD->getMostRecentDecl();
1788 while (D->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None &&
1789 D->getPreviousDecl())
1790 D = D->getPreviousDecl();
1791 return cast<TemplateDecl>(D)->getTemplateParameters();
1801 assert(TemplateParams && TemplateParams->size() > 0 &&
1849 if (SemanticContext->isDependentContext()) {
1857 /*TemplateId-*/ nullptr,
1867 // -- every member template of class T
1881 PrevDecl = (*Previous.begin())->getUnderlyingDecl();
1883 if (PrevDecl && PrevDecl->isTemplateParameter()) {
1895 // We may have found the injected-class-name of a class template,
1899 cast<CXXRecordDecl>(PrevDecl)->isInjectedClassName()) {
1900 PrevDecl = cast<CXXRecordDecl>(PrevDecl->getDeclContext());
1902 = cast<CXXRecordDecl>(PrevDecl)->getDescribedClassTemplate();
1906 ->getSpecializedTemplate();
1914 // function is neither a qualified name nor a template-id, scopes outside
1918 while (!OutermostContext->isFileContext())
1919 OutermostContext = OutermostContext->getLookupParent();
1922 (OutermostContext->Equals(PrevDecl->getDeclContext()) ||
1923 OutermostContext->Encloses(PrevDecl->getDeclContext()))) {
1924 SemanticContext = PrevDecl->getDeclContext();
1933 // declaration of this name as a non-tag type.
1936 while (LookupContext->isTransparentContext())
1937 LookupContext = LookupContext->getLookupParent();
1944 PrevDecl = (*Previous.begin())->getUnderlyingDecl();
1955 PrevClassTemplate->getDeclContext()->getRedeclContext()->Equals(
1956 SemanticContext->getRedeclContext()))) {
1958 Diag(Shadow->getTargetDecl()->getLocation(),
1960 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) << 0;
1970 if (!(TUK == TagUseKind::Friend && CurContext->isDependentContext()) &&
1976 PrevClassTemplate->getTemplateParameters(), /*Complain=*/true,
1983 // the class-key shall agree in kind with the original class
1985 RecordDecl *PrevRecordDecl = PrevClassTemplate->getTemplatedDecl();
1990 << FixItHint::CreateReplacement(KWLoc, PrevRecordDecl->getKindName());
1991 Diag(PrevRecordDecl->getLocation(), diag::note_previous_use);
1992 Kind = PrevRecordDecl->getTagKind();
1997 if (TagDecl *Def = PrevRecordDecl->getDefinition()) {
2002 SkipBody->ShouldSkip = true;
2003 SkipBody->Previous = Def;
2004 auto *Tmpl = cast<CXXRecordDecl>(Hidden)->getDescribedClassTemplate();
2011 Diag(Def->getLocation(), diag::note_previous_definition);
2025 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
2033 if (!(TUK == TagUseKind::Friend && CurContext->isDependentContext()) &&
2038 (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
2039 SemanticContext->isDependentContext())
2048 // template out-of-line.
2064 !(TUK == TagUseKind::Friend && CurContext->isDependentContext());
2069 PrevClassTemplate->getTemplatedDecl() : nullptr,
2073 NewClass->setTemplateParameterListsInfo(
2079 if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) {
2090 NewTemplate->setPreviousDecl(PrevClassTemplate);
2092 NewClass->setDescribedClassTemplate(NewTemplate);
2095 NewTemplate->setModulePrivate();
2098 QualType T = NewTemplate->getInjectedClassNameSpecialization();
2100 assert(T->isDependentType() && "Class template type is not dependent?");
2106 PrevClassTemplate->getInstantiatedFromMemberTemplate())
2107 PrevClassTemplate->setMemberSpecialization();
2111 NewTemplate->getDeclContext()->isRecord())
2115 NewClass->setLexicalDeclContext(CurContext);
2116 NewTemplate->setLexicalDeclContext(CurContext);
2118 if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip))
2119 NewClass->startDefinition();
2125 mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl());
2134 while ((Outer->getFlags() & Scope::TemplateParamScope) != 0)
2135 Outer = Outer->getParent();
2138 if (PrevClassTemplate && PrevClassTemplate->getAccess() != AS_none) {
2139 NewTemplate->setAccess(PrevClassTemplate->getAccess());
2140 NewClass->setAccess(PrevClassTemplate->getAccess());
2143 NewTemplate->setObjectOfFriendDecl();
2146 if (!CurContext->isDependentContext()) {
2147 DeclContext *DC = SemanticContext->getRedeclContext();
2148 DC->makeDeclVisibleInContext(NewTemplate);
2155 Context, CurContext, NewClass->getLocation(), NewTemplate, FriendLoc);
2156 Friend->setAccess(AS_public);
2157 CurContext->addDecl(Friend);
2164 NewTemplate->setInvalidDecl();
2165 NewClass->setInvalidDecl();
2170 if (SkipBody && SkipBody->ShouldSkip)
2171 return SkipBody->Previous;
2177 /// template parameter, which is ill-formed in certain contexts.
2193 // A default template-argument shall not be specified in a
2197 // template-argument, that declaration shall be a definition and shall be
2208 // A default template-argument shall not be specified in the
2209 // template-parameter-lists of the definition of a member of a
2218 // A default template-argument shall not be specified in a
2224 // FIXME: C++0x [temp.param]p9 allows default template-arguments
2238 if (TTP->isParameterPack())
2241 TemplateParameterList *Params = TTP->getTemplateParameters();
2242 for (unsigned I = 0, N = Params->size(); I != N; ++I) {
2243 NamedDecl *P = Params->getParam(I);
2245 if (!TTP->isParameterPack())
2246 if (const TypeConstraint *TC = TTP->getTypeConstraint())
2247 if (TC->hasExplicitTemplateArgs())
2248 for (auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
2256 if (!NTTP->isParameterPack() &&
2257 S.DiagnoseUnexpandedParameterPack(NTTP->getLocation(),
2258 NTTP->getTypeSourceInfo(),
2281 // The set of default template-arguments available for use with a
2290 TemplateParameterList::iterator OldParam = NewParams->end();
2292 OldParam = OldParams->begin();
2295 for (TemplateParameterList::iterator NewParam = NewParams->begin(),
2296 NewParamEnd = NewParams->end();
2313 // Variable used to diagnose non-final parameter packs
2319 if (NewTypeParm->hasDefaultArgument() &&
2321 *this, TPC, NewTypeParm->getLocation(),
2322 NewTypeParm->getDefaultArgument().getSourceRange()))
2323 NewTypeParm->removeDefaultArgument();
2328 if (NewTypeParm->isParameterPack()) {
2329 assert(!NewTypeParm->hasDefaultArgument() &&
2333 NewTypeParm->hasDefaultArgument() &&
2334 (!SkipBody || !SkipBody->ShouldSkip)) {
2335 OldDefaultLoc = OldTypeParm->getDefaultArgumentLoc();
2336 NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
2339 if (!OldTypeParm->getOwningModule())
2345 OldTypeParm->getImportedOwningModule()->getFullModuleName();
2348 } else if (OldTypeParm && OldTypeParm->hasDefaultArgument()) {
2351 NewTypeParm->setInheritedDefaultArgument(Context, OldTypeParm);
2352 PreviousDefaultArgLoc = OldTypeParm->getDefaultArgumentLoc();
2353 } else if (NewTypeParm->hasDefaultArgument()) {
2355 PreviousDefaultArgLoc = NewTypeParm->getDefaultArgumentLoc();
2361 if (!NewNonTypeParm->isParameterPack() &&
2362 DiagnoseUnexpandedParameterPack(NewNonTypeParm->getLocation(),
2363 NewNonTypeParm->getTypeSourceInfo(),
2370 if (NewNonTypeParm->hasDefaultArgument() &&
2372 *this, TPC, NewNonTypeParm->getLocation(),
2373 NewNonTypeParm->getDefaultArgument().getSourceRange())) {
2374 NewNonTypeParm->removeDefaultArgument();
2377 // Merge default arguments for non-type template parameters
2380 if (NewNonTypeParm->isParameterPack()) {
2381 assert(!NewNonTypeParm->hasDefaultArgument() &&
2383 if (!NewNonTypeParm->isPackExpansion())
2386 NewNonTypeParm->hasDefaultArgument() &&
2387 (!SkipBody || !SkipBody->ShouldSkip)) {
2388 OldDefaultLoc = OldNonTypeParm->getDefaultArgumentLoc();
2389 NewDefaultLoc = NewNonTypeParm->getDefaultArgumentLoc();
2391 if (!OldNonTypeParm->getOwningModule())
2397 OldNonTypeParm->getImportedOwningModule()->getFullModuleName();
2400 } else if (OldNonTypeParm && OldNonTypeParm->hasDefaultArgument()) {
2403 NewNonTypeParm->setInheritedDefaultArgument(Context, OldNonTypeParm);
2404 PreviousDefaultArgLoc = OldNonTypeParm->getDefaultArgumentLoc();
2405 } else if (NewNonTypeParm->hasDefaultArgument()) {
2407 PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc();
2421 if (NewTemplateParm->hasDefaultArgument() &&
2423 NewTemplateParm->getLocation(),
2424 NewTemplateParm->getDefaultArgument().getSourceRange()))
2425 NewTemplateParm->removeDefaultArgument();
2430 if (NewTemplateParm->isParameterPack()) {
2431 assert(!NewTemplateParm->hasDefaultArgument() &&
2433 if (!NewTemplateParm->isPackExpansion())
2437 NewTemplateParm->hasDefaultArgument() &&
2438 (!SkipBody || !SkipBody->ShouldSkip)) {
2439 OldDefaultLoc = OldTemplateParm->getDefaultArgument().getLocation();
2440 NewDefaultLoc = NewTemplateParm->getDefaultArgument().getLocation();
2442 if (!OldTemplateParm->getOwningModule())
2448 OldTemplateParm->getImportedOwningModule()->getFullModuleName();
2451 } else if (OldTemplateParm && OldTemplateParm->hasDefaultArgument()) {
2454 NewTemplateParm->setInheritedDefaultArgument(Context, OldTemplateParm);
2456 = OldTemplateParm->getDefaultArgument().getLocation();
2457 } else if (NewTemplateParm->hasDefaultArgument()) {
2460 = NewTemplateParm->getDefaultArgument().getLocation();
2471 Diag((*NewParam)->getLocation(),
2482 // translation unit and the definitions satisfy the [same-meaning
2506 // If a template-parameter of a class template, variable template, or
2508 // template-parameter shall either have a default template argument
2510 Diag((*NewParam)->getLocation(),
2526 for (TemplateParameterList::iterator NewParam = NewParams->begin(),
2527 NewParamEnd = NewParams->end();
2530 TTP->removeDefaultArgument();
2533 NTTP->removeDefaultArgument();
2535 cast<TemplateTemplateParmDecl>(*NewParam)->removeDefaultArgument();
2552 // overall construct type-dependent / a dependent type. This is strictly
2553 // best-effort for now; we may fail to match at all for a dependent type
2566 NamedDecl *ND = Params->getParam(0);
2568 Depth = PD->getDepth();
2571 Depth = PD->getDepth();
2573 Depth = cast<TemplateTemplateParmDecl>(ND)->getDepth();
2587 // Prune out non-type-dependent expressions if requested. This can
2589 // (if a value-dependent expression creates a dependent type), but this
2590 // mode is best-effort only.
2592 if (IgnoreNonTypeDependent && !E->isTypeDependent())
2599 !TL.getType()->isDependentType())
2605 return !Matches(TL.getTypePtr()->getDepth(), TL.getNameLoc());
2609 // For a best-effort search, keep looking until we find a location.
2610 return IgnoreNonTypeDependent || !Matches(T->getDepth());
2616 if (Matches(PD->getDepth()))
2623 dyn_cast<NonTypeTemplateParmDecl>(E->getDecl()))
2624 if (Matches(PD->getDepth(), E->getExprLoc()))
2630 return TraverseType(T->getReplacementType());
2635 return TraverseTemplateArgument(T->getArgumentPack());
2639 return TraverseType(T->getInjectedSpecializationType());
2648 if (!Params->size())
2657 // nested-name-specifier, if any.
2663 if (const Type *CurType = NNS->getAsType()) {
2685 // by the nested-name-specifier and walking out until we run out of types.
2693 T = QualType(SS.getScopeRep()->getAsType(), 0);
2705 if (CXXRecordDecl *Record = T->getAsCXXRecordDecl()) {
2710 Spec->getSpecializationKind() == TSK_ExplicitSpecialization) {
2711 ExplicitSpecLoc = Spec->getLocation();
2714 } else if (Record->getTemplateSpecializationKind()
2716 ExplicitSpecLoc = Record->getLocation();
2720 if (TypeDecl *Parent = dyn_cast<TypeDecl>(Record->getParent()))
2728 = T->getAs<TemplateSpecializationType>()) {
2729 if (TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
2730 if (TypeDecl *Parent = dyn_cast<TypeDecl>(Template->getDeclContext()))
2740 = T->getAs<DependentTemplateSpecializationType>()) {
2741 if (NestedNameSpecifier *NNS = DependentTST->getQualifier())
2742 T = QualType(NNS->getAsType(), 0);
2749 if (const DependentNameType *DependentName = T->getAs<DependentNameType>()){
2750 if (NestedNameSpecifier *NNS = DependentName->getQualifier())
2751 T = QualType(NNS->getAsType(), 0);
2758 if (const EnumType *EnumT = T->getAs<EnumType>()) {
2759 // FIXME: Forward-declared enums require a TSK_ExplicitSpecialization
2761 EnumDecl *Enum = EnumT->getDecl();
2764 if (TypeDecl *Parent = dyn_cast<TypeDecl>(Enum->getParent()))
2774 // to the innermost while checking template-parameter-lists.
2806 ExpectedTemplateLoc = ParamLists[0]->getTemplateLoc();
2837 if (CXXRecordDecl *Record = T->getAsCXXRecordDecl()) {
2840 ExpectedTemplateParams = Partial->getTemplateParameters();
2842 } else if (Record->isDependentType()) {
2843 if (Record->getDescribedClassTemplate()) {
2844 ExpectedTemplateParams = Record->getDescribedClassTemplate()
2845 ->getTemplateParameters();
2854 if (Spec->getSpecializationKind() != TSK_ExplicitSpecialization)
2858 } else if (Record->getTemplateSpecializationKind()) {
2859 if (Record->getTemplateSpecializationKind()
2861 TypeIdx == NumTypes - 1)
2867 = T->getAs<TemplateSpecializationType>()) {
2868 if (TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
2869 ExpectedTemplateParams = Template->getTemplateParameters();
2872 } else if (T->getAs<DependentTemplateSpecializationType>()) {
2886 if (ParamLists[ParamIdx]->size() == 0) {
2887 if (CheckExplicitSpecialization(ParamLists[ParamIdx]->getSourceRange(),
2897 if (TypeIdx == NumTypes - 1)
2901 if (ParamLists[ParamIdx]->size() > 0) {
2904 Diag(ParamLists[ParamIdx]->getTemplateLoc(),
2907 << SourceRange(ParamLists[ParamIdx]->getLAngleLoc(),
2908 ParamLists[ParamIdx]->getRAngleLoc())
2928 // In friend declarations we can have template-ids which don't
2931 // template-id.
2932 if (IsFriend && T->isDependentType()) {
2966 // If there were at least as many template-ids as there were template
2973 DiagnoseMissingExplicitSpecialization(SourceRange(TemplateId->LAngleLoc,
2974 TemplateId->RAngleLoc));
2986 if (ParamIdx < ParamLists.size() - 1) {
2989 for (unsigned I = ParamIdx, E = ParamLists.size() - 1; I != E; ++I) {
2990 if (ParamLists[I]->size() == 0)
2997 Diag(ParamLists[ParamIdx]->getTemplateLoc(),
3000 << SourceRange(ParamLists[ParamIdx]->getTemplateLoc(),
3001 ParamLists[ParamLists.size() - 2]->getRAngleLoc());
3021 // template or a member template that ap- pears in namespace scope, the
3024 // specialize a class member template if its en- closing class templates
3026 if (ParamLists.back()->size() == 0 &&
3027 CheckExplicitSpecialization(ParamLists[ParamIdx]->getSourceRange(),
3038 Diag(Template->getLocation(), diag::note_template_declared_here)
3046 << Template->getDeclName();
3051 for (OverloadedTemplateStorage::iterator I = OST->begin(),
3052 IEnd = OST->end();
3054 Diag((*I)->getLocation(), diag::note_template_declared_here)
3055 << 0 << (*I)->getDeclName();
3068 switch (BTD->getBuiltinTemplateKind()) {
3071 // S<T, 0, ..., N-1>.
3076 if (!OrigType->isDependentType() && !OrigType->isIntegralType(Context)) {
3096 // Expand N into 0 ... N-1.
3105 // If N is negative the program is ill-formed.
3131 "type std::size_t, and hence be non-negative");
3132 // If the Index is out of bounds, the program is ill-formed.
3149 return AliasTemplate->getName() == "enable_if_t" ||
3150 AliasTemplate->getName() == "__enable_if_t";
3161 if (auto BinOp = dyn_cast<BinaryOperator>(Clause->IgnoreParenImpCasts())) {
3162 if (BinOp->getOpcode() == BO_LAnd) {
3163 collectConjunctionTerms(BinOp->getLHS(), Terms);
3164 collectConjunctionTerms(BinOp->getRHS(), Terms);
3172 // The ranges-v3 library uses an odd pattern of a top-level "||" with
3173 // a left-hand side that is value-dependent but never true. Identify
3176 // Top-level '||'.
3177 auto *BinOp = dyn_cast<BinaryOperator>(Cond->IgnoreParenImpCasts());
3180 if (BinOp->getOpcode() != BO_LOr) return Cond;
3182 // With an inner '==' that has a literal on the right-hand side.
3183 Expr *LHS = BinOp->getLHS();
3184 auto *InnerBinOp = dyn_cast<BinaryOperator>(LHS->IgnoreParenImpCasts());
3187 if (InnerBinOp->getOpcode() != BO_EQ ||
3188 !isa<IntegerLiteral>(InnerBinOp->getRHS()))
3192 // CONCEPT_REQUIRES or CONCEPT_REQUIRES_, return the right-hand side
3193 // of the '||', which is the real, user-provided condition.
3194 SourceLocation Loc = InnerBinOp->getExprLoc();
3199 return BinOp->getRHS();
3206 // A PrinterHelper that prints more helpful diagnostics for some sub-expressions
3216 if (DR && DR->getQualifier()) {
3219 DR->getQualifier()->print(OS, Policy, true);
3221 const ValueDecl *VD = DR->getDecl();
3222 OS << VD->getName();
3226 OS, IV->getTemplateArgs().asArray(), Policy,
3227 IV->getSpecializedTemplate()->getTemplateParameters());
3251 Expr *TermAsWritten = Term->IgnoreParenImpCasts();
3259 // a constant-evaluated context.
3264 if (Term->EvaluateAsBooleanCondition(Succeeded, Context) &&
3271 FailedCond = Cond->IgnoreParenImpCasts();
3279 FailedCond->printPretty(Out, &Helper, Policy, 0, "\n", nullptr);
3289 if (DTN && DTN->isIdentifier())
3290 // When building a template-id where the template-name is dependent,
3292 // correct, or the code is ill-formed and will be diagnosed when the
3295 ElaboratedTypeKeyword::None, DTN->getQualifier(), DTN->getIdentifier(),
3317 // Check that the template argument list is well-formed for this
3331 TypeAliasDecl *Pattern = AliasTemplate->getTemplatedDecl();
3332 if (Pattern->isInvalidDecl())
3340 AliasTemplate->getTemplateParameters()->getDepth());
3355 if (!AliasTemplate->getDeclContext()->isFileContext())
3356 SavedContext.emplace(*this, AliasTemplate->getDeclContext());
3359 SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
3360 AliasTemplate->getLocation(), AliasTemplate->getDeclName());
3368 (*DeductionInfo)->hasSFINAEDiagnostic() &&
3369 (*DeductionInfo)->peekSFINAEDiagnostic().second.getDiagID() ==
3381 (*DeductionInfo)->takeSFINAEDiagnostic(OldDiag);
3385 (*DeductionInfo)->addSFINAEDiagnostic(
3389 << FailedCond->getSourceRange());
3419 for (DeclContext *Ctx = CurContext; Ctx; Ctx = Ctx->getLookupParent()) {
3421 if (Ctx->isFileContext()) break;
3430 !Record->getDescribedClassTemplate())
3437 ->getInjectedSpecializationType();
3439 if (CanonType != Injected->getCanonicalTypeInternal())
3455 ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
3461 Context, ClassTemplate->getTemplatedDecl()->getTagKind(),
3462 ClassTemplate->getDeclContext(),
3463 ClassTemplate->getTemplatedDecl()->getBeginLoc(),
3464 ClassTemplate->getLocation(), ClassTemplate, CanonicalConverted,
3466 ClassTemplate->AddSpecialization(Decl, InsertPos);
3467 if (ClassTemplate->isOutOfLine())
3468 Decl->setLexicalDeclContext(ClassTemplate->getLexicalDeclContext());
3471 if (Decl->getSpecializationKind() == TSK_Undeclared &&
3472 ClassTemplate->getTemplatedDecl()->hasAttrs()) {
3479 ClassTemplate->getTemplatedDecl(), Decl);
3488 "type of non-dependent specialization is not a RecordType");
3493 // Build the fully-sugared type for this class template
3509 II = ATN->getDeclName().getAsIdentifierInfo();
3521 // We assumed this undeclared identifier to be an (ADL-only) function
3523 // Try to typo-correct it now.
3527 LookupResult R(*this, ATN->getDeclName(), NameLoc, LookupOrdinaryName);
3543 << ATN->getDeclName());
3567 // A qualified-id that refers to a type and in which the
3568 // nested-name-specifier depends on a template-parameter (14.6.2)
3570 // qualified-id denotes a type, forming an
3571 // elaborated-type-specifier (7.1.5.3).
3579 << SS.getScopeRep() << TemplateII->getName()
3583 << SS.getScopeRep() << TemplateII->getName();
3593 // Per C++ [class.qual]p2, if the template-id was an injected-class-name,
3598 if (LookupRD && LookupRD->getIdentifier() == TemplateII) {
3603 << TemplateII << 0 /*injected-class-name used as template name*/
3618 assert(SS.getScopeRep() == DTN->getQualifier());
3620 ElaboratedTypeKeyword::None, DTN->getQualifier(), DTN->getIdentifier(),
3622 // Build type-source information.
3623 TypeLocBuilder TLB;
3625 = TLB.push<DependentTemplateSpecializationTypeLoc>(T);
3634 return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
3641 // Build type-source information.
3642 TypeLocBuilder TLB;
3644 TLB.push<TemplateSpecializationTypeLoc>(SpecTy);
3652 // Create an elaborated-type-specifier containing the nested-name-specifier.
3656 ElaboratedTypeLoc ElabTL = TLB.push<ElaboratedTypeLoc>(ElTy);
3660 return CreateParsedType(ElTy, TLB.getTypeSourceInfo(Context, ElTy));
3688 assert(SS.getScopeRep() == DTN->getQualifier());
3690 Keyword, DTN->getQualifier(), DTN->getIdentifier(),
3693 // Build type-source information.
3694 TypeLocBuilder TLB;
3696 = TLB.push<DependentTemplateSpecializationTypeLoc>(T);
3705 return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
3711 // If the identifier resolves to a typedef-name or the simple-template-id
3713 // elaborated-type-specifier is ill-formed.
3716 Diag(TAT->getLocation(), diag::note_declared_at);
3724 if (const RecordType *RT = Result->getAs<RecordType>()) {
3725 RecordDecl *D = RT->getDecl();
3727 IdentifierInfo *Id = D->getIdentifier();
3730 if (!isAcceptableTagRedeclaration(D, TagKind, TUK == TagUseKind::Definition,
3734 << FixItHint::CreateReplacement(SourceRange(TagLoc), D->getKindName());
3735 Diag(D->getLocation(), diag::note_previous_use);
3739 // Provide source-location information for the template specialization.
3740 TypeLocBuilder TLB;
3742 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3750 // Construct an elaborated type containing the nested-name-specifier (if any)
3753 ElaboratedTypeLoc ElabTL = TLB.push<ElaboratedTypeLoc>(Result);
3756 return CreateParsedType(Result, TLB.getTypeSourceInfo(Context, Result));
3764 static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D);
3781 Arg.getAsType()->getAs<TemplateTypeParmType>();
3783 TPT->getDepth() == Depth && TPT->getIndex() == Index;
3788 if (!DRE || !DRE->getDecl())
3791 dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl());
3792 return NTTP && NTTP->getDepth() == Depth && NTTP->getIndex() == Index;
3799 return TTP && TTP->getDepth() == Depth && TTP->getIndex() == Index;
3806 if (Params->size() != Args.size())
3809 unsigned Depth = Params->getDepth();
3816 if (Params->getParam(I)->isParameterPack()) {
3818 !Arg.pack_begin()->isPackExpansion())
3820 Arg = Arg.pack_begin()->getPackExpansionPattern();
3832 if (Partial->getDeclContext()->isDependentContext())
3836 // for non-substitution-failure issues?
3837 TemplateDeductionInfo Info(Partial->getLocation());
3841 auto *Template = Partial->getSpecializedTemplate();
3842 S.Diag(Partial->getLocation(),
3859 Template->getAssociatedConstraints(TemplateAC);
3860 Partial->getAssociatedConstraints(PartialAC);
3870 NamedDecl *Param = TemplateParams->getParam(I);
3871 if (Param->getDeclName())
3872 S.Diag(Param->getLocation(), diag::note_non_deducible_parameter)
3873 << Param->getDeclName();
3875 S.Diag(Param->getLocation(), diag::note_non_deducible_parameter)
3886 // - The specialization shall be more specialized than the primary
3891 // - Each template-parameter shall appear at least once in the
3892 // template-id outside a non-deduced context.
3895 // deduced because of the structure of its template-parameter-list
3896 // and the template-id, the program is ill-formed.
3897 auto *TemplateParams = Partial->getTemplateParameters();
3898 llvm::SmallBitVector DeducibleParams(TemplateParams->size());
3899 S.MarkUsedTemplateParameters(Partial->getTemplateArgs(), true,
3900 TemplateParams->getDepth(), DeducibleParams);
3903 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
3904 S.Diag(Partial->getLocation(), diag::ext_partial_specs_not_deducible)
3907 << SourceRange(Partial->getLocation(),
3908 Partial->getTemplateArgsAsWritten()->RAngleLoc);
3926 // default-argument shall be deducible from the parameter-type-list of the
3928 auto *TemplateParams = TD->getTemplateParameters();
3929 llvm::SmallBitVector DeducibleParams(TemplateParams->size());
3931 for (unsigned I = 0; I != TemplateParams->size(); ++I) {
3933 auto *Param = TemplateParams->getParam(I);
3934 if (Param->isParameterPack() || hasVisibleDefaultArgument(Param))
3939 unsigned NumNonDeducible = DeducibleParams.size() - DeducibleParams.count();
3940 Diag(TD->getLocation(), diag::err_deduction_guide_template_not_deducible)
3947 Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous,
3950 // D must be variable template id.
3951 assert(D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId &&
3954 TemplateIdAnnotation *TemplateId = D.getName().TemplateId;
3957 SourceLocation TemplateNameLoc = D.getIdentifierLoc();
3958 SourceLocation LAngleLoc = TemplateId->LAngleLoc;
3959 SourceLocation RAngleLoc = TemplateId->RAngleLoc;
3961 TemplateName Name = TemplateId->Template.get();
3963 // The template-id must name a variable template.
3969 FnTemplate = *OTS->begin();
3973 return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method)
3974 << FnTemplate->getDeclName();
3975 return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template)
3987 // Check that the template argument list is well-formed for this
4009 << VarTemplate->getDeclName();
4013 if (isSameAsPrimaryTemplate(VarTemplate->getTemplateParameters(),
4016 !TemplateParams->hasAssociatedConstraints())) {
4019 // -- The argument list of the specialization shall not be identical
4023 << /*is definition*/(SC != SC_Extern && !CurContext->isRecord())
4035 PrevDecl = VarTemplate->findPartialSpecialization(
4038 PrevDecl = VarTemplate->findSpecialization(CanonicalConverted, InsertPos);
4049 if (PrevDecl && PrevDecl->getSpecializationKind() == TSK_Undeclared) {
4055 Specialization->setLocation(TemplateNameLoc);
4063 Context, VarTemplate->getDeclContext(), TemplateKWLoc,
4064 TemplateNameLoc, TemplateParams, VarTemplate, DI->getType(), DI, SC,
4066 Partial->setTemplateArgsAsWritten(TemplateArgs);
4069 VarTemplate->AddPartialSpecialization(Partial, InsertPos);
4074 if (PrevPartial && PrevPartial->getInstantiatedFromMember())
4075 PrevPartial->setMemberSpecialization();
4082 Context, VarTemplate->getDeclContext(), TemplateKWLoc, TemplateNameLoc,
4083 VarTemplate, DI->getType(), DI, SC, CanonicalConverted);
4084 Specialization->setTemplateArgsAsWritten(TemplateArgs);
4087 VarTemplate->AddSpecialization(Specialization, InsertPos);
4096 if (PrevDecl && PrevDecl->getPointOfInstantiation().isValid()) {
4098 for (Decl *Prev = PrevDecl; Prev; Prev = Prev->getPreviousDecl()) {
4111 Diag(PrevDecl->getPointOfInstantiation(),
4113 << (PrevDecl->getTemplateSpecializationKind() !=
4119 Specialization->setLexicalDeclContext(CurContext);
4124 CurContext->addDecl(Specialization);
4127 Specialization->setSpecializationKind(TSK_ExplicitSpecialization);
4132 else if (Specialization->isStaticDataMember() &&
4133 Specialization->isOutOfLine())
4134 Specialization->setAccess(VarTemplate->getAccess());
4141 /// a given template-id.
4154 // Check that the template argument list is well-formed for this template.
4164 if (Template->getDeclContext()->isDependentContext() ||
4173 Template->findSpecialization(CanonicalConverted, InsertPos)) {
4183 VarDecl *InstantiationPattern = Template->getTemplatedDecl();
4198 Template->getPartialSpecializations(PartialSpecs);
4207 // Store the failed-deduction information for use in diagnostics, later.
4208 // TODO: Actually use the failed-deduction info?
4223 // -- If exactly one matching specialization is found, the
4227 // -- If more than one matching specialization is found, the
4233 // ambiguous and the program is ill-formed.
4237 if (getMoreSpecializedPartialSpecialization(P->Partial, Best->Partial,
4239 P->Partial)
4249 P->Partial, Best->Partial,
4250 PointOfInstantiation) != Best->Partial) {
4258 InstantiationPattern = Best->Partial;
4259 PartialSpecArgs = Best->Args;
4261 // -- If no match is found, the instantiation is generated
4263 // InstantiationPattern = Template->getTemplatedDecl();
4267 // Note that we do not instantiate a definition until we see an odr-use
4278 Decl->setInvalidDecl();
4284 Diag(P.Partial->getLocation(), diag::note_partial_spec_match)
4285 << getTemplateArgumentBindingsText(P.Partial->getTemplateParameters(),
4290 if (VarTemplatePartialSpecializationDecl *D =
4292 Decl->setInstantiationOf(D, PartialSpecArgs);
4314 if (!Var->getTemplateSpecializationKind())
4315 Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation,
4327 NoteTemplateLocation(*TD, TD->getTemplateParameters()->getSourceRange());
4360 Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
4375 NamedConcept, {NamedConcept->getConstraintExpr()}, MLTAL,
4377 TemplateArgs->getRAngleLoc()),
4407 // Non-function templates require a template argument list.
4445 if (ULE->getType() == Context.OverloadTy && R.isSingleResult() &&
4446 !R.getFoundDecl()->getAsFunction())
4447 ULE->setType(Context.UnresolvedTemplateTy);
4492 if (TemplateKWLoc.isValid() && S && !S->getTemplateParamParent())
4511 // a template, the program is ill-formed. [Note: the keyword
4512 // template may not be applied to non-template members of class
4513 // templates. -end note ] [ Note: as is the case with the
4516 // nested-name-specifier or the expression on the left of the ->
4517 // or . is not dependent on a template-parameter, or the use
4518 // does not appear in the scope of a template. -end note]
4521 // the "template" keyword prior to a template-name that was not a
4530 // We resolved this to a (non-dependent) template name. Return it.
4534 Name.Identifier && LookupRD->getIdentifier() == Name.Identifier) {
4537 // nested-name-specifier nominates a class C, if the name specified
4538 // [...] is the injected-class-name of C, [...] the name is instead
4543 // injected-class-name as naming the template.
4547 << 0 /*injected-class-name used as template name*/
4562 // cases where it finds a non-template.
4622 // A template-argument for a template-parameter which is a
4623 // type shall be a type-id.
4644 SS.Adopt(ArgExpr->getQualifierLoc());
4645 NameInfo = ArgExpr->getNameInfo();
4648 if (ArgExpr->isImplicitAccess()) {
4649 SS.Adopt(ArgExpr->getQualifierLoc());
4650 NameInfo = ArgExpr->getMemberNameInfo();
4673 TypeLocBuilder TLB;
4674 DependentNameTypeLoc TL = TLB.push<DependentNameTypeLoc>(ArgType);
4678 TSI = TLB.getTypeSourceInfo(Context, ArgType);
4714 // Objective-C ARC:
4715 // If an explicitly-specified template argument type is a lifetime type
4718 ArgType->isObjCLifetimeType() &&
4741 /// template-id we are checking.
4744 /// terminates the template-id.
4761 Output = Param->getDefaultArgument();
4764 // on the previously-computed template arguments.
4775 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
4779 if (const auto *Rec = dyn_cast<CXXRecordDecl>(Template->getDeclContext()))
4780 ForLambdaCallOperator = Rec->isLambda();
4781 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
4785 Param->getDefaultArgumentLoc(),
4786 Param->getDeclName()))
4794 /// the given non-type template parameter.
4803 /// template-id we are checking.
4806 /// terminates the template-id.
4808 /// \param Param the non-type template parameter whose default we are
4830 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
4833 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
4836 return SemaRef.SubstTemplateArgument(Param->getDefaultArgument(),
4850 /// template-id we are checking.
4853 /// terminates the template-id.
4861 /// \param QualifierLoc Will be set to the nested-name-specifier (with
4862 /// source-location information) that precedes the template name.
4880 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
4883 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
4884 // Substitute into the nested-name-specifier first,
4885 QualifierLoc = Param->getDefaultArgument().getTemplateQualifierLoc();
4895 Param->getDefaultArgument().getArgument().getAsTemplate(),
4896 Param->getDefaultArgument().getTemplateNameLoc(),
4949 TempTempParm->getDefaultArgument().getTemplateQualifierLoc(),
4950 TempTempParm->getDefaultArgument().getTemplateNameLoc());
4953 /// Convert a template-argument that we parsed as a type into a template, if
4954 /// possible. C++ permits injected-class-names to perform dual service as
4958 // Extract and step over any surrounding nested-name-specifier.
4961 if (ETLoc.getTypePtr()->getKeyword() != ElaboratedTypeKeyword::None)
4967 // If this type was written as an injected-class-name, it can be used as a
4970 return TemplateArgumentLoc(Context, InjLoc.getTypePtr()->getTemplateName(),
4973 // If this type was written as an injected-class-name, it may have been
4976 // template specialization, it must have come from an injected-class-name.
4981 TemplateName(CTSD->getSpecializedTemplate()),
4999 // Check non-type template parameters.
5001 // Do substitution on the type of the non-type template parameter
5004 QualType NTTPType = NTTP->getType();
5005 if (NTTP->isParameterPack() && NTTP->isExpandedParameterPack())
5006 NTTPType = NTTP->getExpansionType(ArgumentPackIndex);
5008 if (NTTPType->isInstantiationDependentType() &&
5010 !Template->getDeclContext()->isDependentContext()) {
5011 // Do substitution on the type of the non-type template parameter.
5021 if (auto *PET = NTTPType->getAs<PackExpansionType>()) {
5024 NTTPType = SubstType(PET->getPattern(), MLTAL, NTTP->getLocation(),
5025 NTTP->getDeclName());
5027 NTTPType = SubstType(NTTPType, MLTAL, NTTP->getLocation(),
5028 NTTP->getDeclName());
5031 // If that worked, check the non-type template parameter type
5035 NTTP->getLocation());
5081 // We were given a template template argument. It may not be ill-formed;
5088 // know that we need a non-type template argument, convert this
5091 DeclarationNameInfo NameInfo(DTN->getIdentifier(),
5096 // FIXME: the template-template arg was a DependentTemplateName,
5125 // therefore cannot be a non-type template argument.
5133 // We have a non-type template parameter but the template
5137 // In a template-argument, an ambiguity between a type-id and
5138 // an expression is resolved to a type-id, regardless of the
5139 // form of the corresponding template-parameter.
5145 if (T->isFunctionType())
5164 TemplateParameterList *Params = TempParm->getTemplateParameters();
5165 if (TempParm->isExpandedParameterPack())
5166 Params = TempParm->getExpansionTemplateParameters(ArgumentPackIndex);
5169 // template parameter, since previously-supplied template arguments
5172 // FIXME: Skip this if the parameters aren't instantiation-dependent.
5192 // When [the injected-class-name] is used [...] as a template-argument for
5193 // a template template-parameter [...] it refers to the class template
5197 Context, Arg.getTypeSourceInfo()->getTypeLoc());
5229 llvm_unreachable("non-type argument with template template parameter");
5242 const TemplateParmDecl *D,
5246 D = cast<TemplateParmDecl>(cast<TemplateDecl>(TD->getMostRecentDecl())
5247 ->getTemplateParameters()
5248 ->getParam(D->getIndex()));
5253 if (D->hasDefaultArgument() && !S.hasReachableDefaultArgument(D, &Modules)) {
5255 D->getDefaultArgumentLoc(), Modules,
5264 TemplateParameterList *Params = TD->getTemplateParameters();
5270 S.NoteTemplateLocation(*TD, Params->getSourceRange());
5274 /// Check that the given template argument list is well-formed
5297 // [...] The type and form of each template-argument specified in
5298 // a template-id shall match the type and form specified for the
5300 // template-parameter-list.
5306 for (TemplateParameterList::iterator Param = Params->begin(),
5307 ParamEnd = Params->end();
5332 NoteTemplateLocation(*Template, Params->getSourceRange());
5348 CanonicalConverted, Params->getDepth()));
5352 (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
5363 // As for concepts - we cannot normalize constraints where this
5376 if ((*Param)->isTemplateParameterPack()) {
5388 // If we just saw a pack expansion into a non-pack, then directly convert
5422 if ((*Param)->isTemplateParameterPack() && !SugaredArgumentPack.empty()) {
5433 if ((*Param)->isTemplateParameterPack()) {
5437 // A non-expanded parameter pack before the end of the parameter list
5438 // only occurs for an ill-formed template parameter list, unless we've
5442 (Template->getMostRecentDecl()->getKind() != Decl::Kind::Concept) &&
5503 TempParm->getDefaultArgument().getTemplateNameLoc());
5540 CurrentInstantiationScope->getPartiallySubstitutedPack()) {
5557 NoteTemplateLocation(*Template, Params->getSourceRange());
5568 // re-instantiate constraints outside of normal instantiation.
5569 DeclContext *NewContext = Template->getDeclContext();
5574 NewContext = Decl::castToDeclContext(TD->getTemplatedDecl());
5579 dyn_cast_or_null<CXXMethodDecl>(Template->getTemplatedDecl()))
5580 ThisQuals = Method->getMethodQualifiers();
5636 return Visit(T->getElementType());
5640 return Visit(T->getPointeeType());
5645 return Visit(T->getPointeeType());
5650 return Visit(T->getPointeeType());
5655 return Visit(T->getPointeeType());
5660 return Visit(T->getPointeeType()) || Visit(QualType(T->getClass(), 0));
5665 return Visit(T->getElementType());
5670 return Visit(T->getElementType());
5675 return Visit(T->getElementType());
5680 return Visit(T->getElementType());
5685 return Visit(T->getElementType());
5690 return Visit(T->getElementType());
5695 return Visit(T->getPointeeType());
5699 return Visit(T->getElementType());
5704 return Visit(T->getElementType());
5708 return Visit(T->getElementType());
5713 return Visit(T->getElementType());
5718 for (const auto &A : T->param_types()) {
5723 return Visit(T->getReturnType());
5728 return Visit(T->getReturnType());
5741 return Visit(T->getUnmodifiedType());
5759 return Visit(T->getDeducedType());
5764 return Visit(T->getDeducedType());
5768 return VisitTagDecl(T->getDecl());
5772 return VisitTagDecl(T->getDecl());
5792 return VisitTagDecl(T->getDecl());
5797 return VisitNestedNameSpecifier(T->getQualifier());
5802 if (auto *Q = T->getQualifier())
5809 return Visit(T->getPattern());
5827 return Visit(T->getValueType());
5849 if (Tag->getDeclContext()->isFunctionOrMethod()) {
5858 if (!Tag->hasNameForLinkage()) {
5863 S.Diag(Tag->getLocation(), diag::note_template_unnamed_type_here);
5873 if (NNS->getPrefix() && VisitNestedNameSpecifier(NNS->getPrefix()))
5876 switch (NNS->getKind()) {
5886 return Visit(QualType(NNS->getAsType(), 0));
5893 QualType Arg = ArgInfo->getType();
5894 SourceRange SR = ArgInfo->getTypeLoc().getSourceRange();
5897 if (CanonArg->isVariablyModifiedType()) {
5906 // template-argument for a template type-parameter.
5910 if (LangOpts.CPlusPlus11 || CanonArg->hasUnnamedOrLocalType()) {
5930 if (Arg->isValueDependent() || Arg->isTypeDependent())
5933 // dllimport'd entities aren't constant but are available inside of template
5935 if (Entity && Entity->hasAttr<DLLImportAttr>())
5938 if (!S.isCompleteType(Arg->getExprLoc(), ParamType))
5954 if (!Arg->EvaluateAsRValue(EvalResult, S.Context) ||
5956 SourceLocation DiagLoc = Arg->getExprLoc();
5968 << Arg->getType() << Arg->getSourceRange();
5977 // - an address constant expression of type std::nullptr_t
5978 if (Arg->getType()->isNullPtrType())
5981 // - a constant expression that evaluates to a null pointer value (4.10); or
5982 // - a constant expression that evaluates to a null member pointer value
5989 if (S.Context.hasSameUnqualifiedType(Arg->getType(), ParamType) ||
5990 S.IsQualificationConversion(Arg->getType(), ParamType, false,
5996 S.Diag(Arg->getExprLoc(), diag::err_template_arg_wrongtype_null_constant)
5997 << Arg->getType() << ParamType << Arg->getSourceRange();
6006 S.Diag(Arg->getExprLoc(), diag::err_template_arg_invalid)
6014 if (Arg->isNullPointerConstant(S.Context, Expr::NPC_NeverValueDependent)) {
6016 S.Diag(Arg->getExprLoc(), diag::err_template_arg_untyped_null_constant)
6017 << ParamType << FixItHint::CreateInsertion(Arg->getBeginLoc(), Code)
6018 << FixItHint::CreateInsertion(S.getLocForEndOfToken(Arg->getEndLoc()),
6024 // FIXME: If we ever want to support general, address-constant expressions
6025 // as non-type template arguments, we should return the ExprResult here to
6036 if (ParamType->isPointerType() &&
6037 !ParamType->castAs<PointerType>()->getPointeeType()->isFunctionType() &&
6040 // For pointer-to-object types, qualification conversions are
6043 if (const ReferenceType *ParamRef = ParamType->getAs<ReferenceType>()) {
6044 if (!ParamRef->getPointeeType()->isFunctionType()) {
6046 // For a non-type template-parameter of type reference to
6048 // reference may be more cv-qualified than the (otherwise
6049 // identical) type of the template- argument. The
6050 // template-parameter is bound directly to the
6051 // template-argument, which shall be an lvalue.
6054 unsigned ParamQuals = ParamRef->getPointeeType().getCVRQualifiers();
6058 S.Diag(Arg->getBeginLoc(),
6060 << ParamType << Arg->getType() << Arg->getSourceRange();
6073 if (ParamType->isReferenceType())
6074 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_no_ref_bind)
6075 << ParamType << ArgIn->getType() << Arg->getSourceRange();
6077 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_convertible)
6078 << ArgIn->getType() << ParamType << Arg->getSourceRange();
6094 QualType ArgType = Arg->getType();
6100 // dereference and address-of operators.
6101 Arg = Arg->IgnoreParenCasts();
6107 UnaryOperatorKind UnOpKind = UnOp->getOpcode();
6111 Arg = UnOp->getSubExpr()->IgnoreParenCasts();
6114 FirstOpLoc = UnOp->getOperatorLoc();
6121 S.Diag(ArgIn->getBeginLoc(), diag::ext_ms_deref_template_argument)
6122 << ArgIn->getSourceRange();
6126 else if (Arg->getType()->isPointerType()) {
6130 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_decl_ref)
6131 << Arg->getSourceRange();
6136 Arg = Arg->IgnoreImpCasts();
6140 // A template-argument for a non-type, non-template
6141 // template-parameter shall be one of: [...]
6143 // -- the address of an object or function with external
6145 // template-ids but excluding non-static class members,
6146 // expressed as & id-expression where the & is optional if
6148 // corresponding template-parameter is a reference; or
6151 // See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#773
6155 S.Diag(Arg->getBeginLoc(),
6159 << Arg->getSourceRange();
6163 Arg = Parens->getSubExpr();
6168 Arg = subst->getReplacement()->IgnoreImpCasts();
6171 if (UnOp->getOpcode() == UO_AddrOf) {
6172 Arg = UnOp->getSubExpr();
6174 AddrOpLoc = UnOp->getOperatorLoc();
6180 Arg = subst->getReplacement()->IgnoreImpCasts();
6185 Entity = DRE->getDecl();
6187 Entity = CUE->getGuidDecl();
6190 if (ParamType->isPointerType() || ParamType->isNullPtrType()) {
6194 S.Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
6212 if (Arg->isValueDependent()) {
6220 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_decl_ref)
6221 << Arg->getSourceRange();
6226 // Cannot refer to non-static data members
6228 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_field)
6229 << Entity << Arg->getSourceRange();
6234 // Cannot refer to non-static member functions
6236 if (!Method->isStatic()) {
6237 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_method)
6238 << Method << Arg->getSourceRange();
6248 // A non-type template argument must refer to an object or function.
6251 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_object_or_func)
6252 << Arg->getSourceRange();
6253 S.Diag(Entity->getLocation(), diag::note_template_arg_refers_here);
6258 if (Entity->getFormalLinkage() == Linkage::Internal) {
6259 S.Diag(Arg->getBeginLoc(),
6263 << !Func << Entity << Arg->getSourceRange();
6264 S.Diag(Entity->getLocation(), diag::note_template_arg_internal_object)
6266 } else if (!Entity->hasLinkage()) {
6267 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_object_no_linkage)
6268 << !Func << Entity << Arg->getSourceRange();
6269 S.Diag(Entity->getLocation(), diag::note_template_arg_internal_object)
6276 if (Var->getType()->isReferenceType()) {
6277 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_reference_var)
6278 << Var->getType() << Arg->getSourceRange();
6284 if (Var->getTLSKind()) {
6285 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_thread_local)
6286 << Arg->getSourceRange();
6287 S.Diag(Var->getLocation(), diag::note_template_arg_refers_here);
6292 if (AddressTaken && ParamType->isReferenceType()) {
6293 // If we originally had an address-of operator, but the
6295 // like they will work) drop the address-of operator.
6296 if (!S.Context.hasSameUnqualifiedType(Entity->getType(),
6309 ArgType = Entity->getType();
6314 if (!AddressTaken && ParamType->isPointerType()) {
6316 // Function-to-pointer decay.
6317 ArgType = S.Context.getPointerType(Func->getType());
6318 } else if (Entity->getType()->isArrayType()) {
6319 // Array-to-pointer decay.
6320 ArgType = S.Context.getArrayDecayedType(Entity->getType());
6325 ArgType = S.Context.getPointerType(Entity->getType());
6327 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_address_of)
6333 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_address_of)
6334 << ParamType << FixItHint::CreateInsertion(Arg->getBeginLoc(), "&");
6347 TemplateArgument(cast<ValueDecl>(Entity->getCanonicalDecl()),
6349 S.MarkAnyDeclReferenced(Arg->getBeginLoc(), Entity, false);
6367 // A template-argument for a non-type, non-template
6368 // template-parameter shall be one of: [...]
6370 // -- a pointer to member expressed as described in 5.3.1.
6374 // See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#773
6378 S.Diag(Arg->getBeginLoc(),
6382 << Arg->getSourceRange();
6386 Arg = Parens->getSubExpr();
6391 Arg = subst->getReplacement()->IgnoreImpCasts();
6393 // A pointer-to-member constant written &Class::member.
6395 if (UnOp->getOpcode() == UO_AddrOf) {
6396 DRE = dyn_cast<DeclRefExpr>(UnOp->getSubExpr());
6397 if (DRE && !DRE->getQualifier())
6401 // A constant of pointer-to-member type.
6403 ValueDecl *VD = DRE->getDecl();
6404 if (VD->getType()->isMemberPointerType()) {
6406 if (Arg->isTypeDependent() || Arg->isValueDependent()) {
6413 TemplateArgument(cast<ValueDecl>(VD->getCanonicalDecl()),
6423 ValueDecl *Entity = DRE ? DRE->getDecl() : nullptr;
6431 S.Diag(ResultArg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
6441 if (S.IsQualificationConversion(ResultArg->getType(),
6445 ResultArg->getValueKind())
6448 ResultArg->getType(), ParamType.getNonReferenceType())) {
6450 S.Diag(ResultArg->getBeginLoc(), diag::err_template_arg_not_convertible)
6451 << ResultArg->getType() << ParamType << ResultArg->getSourceRange();
6457 return S.Diag(Arg->getBeginLoc(),
6459 << Arg->getSourceRange();
6461 if (isa<FieldDecl>(DRE->getDecl()) ||
6462 isa<IndirectFieldDecl>(DRE->getDecl()) ||
6463 isa<CXXMethodDecl>(DRE->getDecl())) {
6464 assert((isa<FieldDecl>(DRE->getDecl()) ||
6465 isa<IndirectFieldDecl>(DRE->getDecl()) ||
6466 cast<CXXMethodDecl>(DRE->getDecl())
6467 ->isImplicitObjectMemberFunction()) &&
6468 "Only non-static member pointers can make it here");
6470 // Okay: this is the address of a non-static member, and therefore
6472 if (Arg->isTypeDependent() || Arg->isValueDependent()) {
6477 ValueDecl *D = DRE->getDecl();
6478 SugaredConverted = TemplateArgument(D, ParamType);
6480 TemplateArgument(cast<ValueDecl>(D->getCanonicalDecl()),
6487 S.Diag(Arg->getBeginLoc(), diag::err_template_arg_not_pointer_to_member_form)
6488 << Arg->getSourceRange();
6489 S.Diag(DRE->getDecl()->getLocation(), diag::note_template_arg_refers_here);
6498 SourceLocation StartLoc = Arg->getBeginLoc();
6501 DeducedType *DeducedT = ParamType->getContainedDeducedType();
6502 if (getLangOpts().CPlusPlus17 && DeducedT && !DeducedT->isDeduced()) {
6507 // expression is merely instantiation-dependent; is this enough?
6508 if (Arg->isTypeDependent()) {
6510 if (AT && AT->isDecltypeAuto()) {
6519 // the type is dependent, in order to check the types of non-type template
6523 DeductionArg = PE->getPattern();
6525 Context.getTrivialTypeSourceInfo(ParamType, Param->getLocation());
6530 DeductionArg->getBeginLoc(), /*DirectInit*/false, DeductionArg);
6537 TemplateDeductionInfo Info(DeductionArg->getExprLoc(),
6538 Param->getDepth() + 1);
6541 DeduceAutoType(TSI->getTypeLoc(), DeductionArg, ParamType, Info,
6544 // immediately-declared constraint of the auto type is
6553 Diag(Arg->getExprLoc(),
6555 << Param->getDeclName() << Param->getType() << Arg->getType()
6556 << Arg->getSourceRange();
6565 ParamType = CheckNonTypeTemplateParameterType(ParamType, Arg->getExprLoc());
6572 // We should have already dropped all cv-qualifiers by now.
6574 "non-type template parameter type cannot be qualified");
6578 (ParamType->isReferenceType()
6580 Arg->getType())
6581 : !Context.hasSameUnqualifiedType(ParamType, Arg->getType()))) {
6584 // template parameter with some unique (non-dependent) placeholder.
6589 if ((ParamType->isDependentType() || Arg->isTypeDependent()) &&
6590 !Arg->getType()->getContainedDeducedType()) {
6601 << Arg->getType()
6608 // type-dependent, there's nothing we can check now.
6609 if (ParamType->isDependentType() || Arg->isTypeDependent()) {
6613 Arg = PE->getPattern();
6616 ParamType->isLValueReferenceType() ? VK_LValue
6617 : ParamType->isRValueReferenceType() ? VK_XValue
6624 PackExpansionExpr(E.get()->getType(), E.get(), PE->getEllipsisLoc(),
6625 PE->getNumExpansions());
6642 Expr *InnerArg = Arg->IgnoreParenImpCasts();
6643 if (ParamType->isRecordType() && isa<DeclRefExpr>(InnerArg) &&
6644 Context.hasSameUnqualifiedType(ParamType, InnerArg->getType())) {
6645 NamedDecl *ND = cast<DeclRefExpr>(InnerArg)->getDecl();
6650 TemplateArgument(TPO->getCanonicalDecl(), CanonParamType);
6662 // a constant-evaluated context.
6667 if (isa<InitListExpr>(Arg) || ParamType->isRecordType()) {
6669 Arg->getBeginLoc(), /*DirectInit=*/false, Arg);
6680 Arg = ActOnFinishFullExpr(Result.get(), Arg->getBeginLoc(),
6689 // A template-argument for a non-type template parameter shall be
6690 // a converted constant expression of the type of the template-parameter.
6702 // For a value-dependent argument, CheckConvertedConstantExpression is
6704 if (ArgResult.get()->isValueDependent()) {
6721 // For a non-type template-parameter of pointer or reference type,
6723 assert(ParamType->isPointerType() || ParamType->isReferenceType() ||
6724 ParamType->isNullPtrType());
6725 // -- a temporary object
6726 // -- a string literal
6727 // -- the result of a typeid expression, or
6728 // -- a predefined __func__ variable
6732 Diag(Arg->getBeginLoc(), diag::err_template_arg_not_decl_ref)
6733 << Arg->getSourceRange();
6738 VD->getType()->isArrayType() &&
6740 !Value.isLValueOnePastTheEnd() && ParamType->isPointerType()) {
6743 cast<ValueDecl>(VD->getCanonicalDecl()), CanonParamType);
6747 // -- a subobject [until C++20]
6755 assert((VD || !ParamType->isReferenceType()) &&
6757 assert((!VD || !ParamType->isNullPtrType()) &&
6758 "non-null value of type nullptr_t?");
6772 // as a non-type template-argument. If a non-type
6773 // template-argument cannot be converted to the type of the
6774 // corresponding template-parameter then the program is
6775 // ill-formed.
6776 if (ParamType->isIntegralOrEnumerationType()) {
6778 // -- for a non-type template-parameter of integral or
6783 // -- for a non-type template-parameter of integral or
6789 // A template-argument for a non-type, non-template template-parameter
6792 // -- for a non-type template-parameter of integral or enumeration
6794 // template-parameter; or
6802 // We can't check arbitrary value-dependent arguments.
6803 if (ArgResult.get()->isValueDependent()) {
6811 // always a no-op, except when the parameter type is bool. In
6814 if (const EnumType *Enum = IntegerType->getAs<EnumType>())
6815 IntegerType = Enum->getDecl()->getIntegerType();
6816 Value = Value.extOrTrunc(IntegerType->isBitIntType()
6831 QualType ArgType = Arg->getType();
6834 // A template-argument for a non-type, non-template
6835 // template-parameter shall be one of:
6837 // -- an integral constant-expression of integral or enumeration
6839 // -- the name of a non-type template-parameter; or
6841 if (!ArgType->isIntegralOrEnumerationType()) {
6842 Diag(Arg->getBeginLoc(), diag::err_template_arg_not_integral_or_enumeral)
6843 << ArgType << Arg->getSourceRange();
6846 } else if (!Arg->isValueDependent()) {
6871 } else if (ParamType->isBooleanType()) {
6872 // This is an integral-to-boolean conversion.
6875 !ParamType->isEnumeralType()) {
6880 Diag(Arg->getBeginLoc(), diag::err_template_arg_not_convertible)
6881 << Arg->getType() << ParamType << Arg->getSourceRange();
6889 if (Arg->isValueDependent()) {
6890 // The argument is value-dependent. Create a new
6899 if (const EnumType *Enum = IntegerType->getAs<EnumType>()) {
6900 IntegerType = Enum->getDecl()->getIntegerType();
6903 if (ParamType->isBooleanType()) {
6909 Value.setIsSigned(IntegerType->isSignedIntegerOrEnumerationType());
6915 unsigned AllowedBits = IntegerType->isBitIntType()
6920 Value.setIsSigned(IntegerType->isSignedIntegerOrEnumerationType());
6923 if (IntegerType->isUnsignedIntegerOrEnumerationType() &&
6925 Diag(Arg->getBeginLoc(), diag::warn_template_arg_negative)
6926 << toString(OldValue, 10) << toString(Value, 10) << Param->getType()
6927 << Arg->getSourceRange();
6933 if (IntegerType->isUnsignedIntegerOrEnumerationType())
6940 Diag(Arg->getBeginLoc(), diag::warn_template_arg_too_large)
6941 << toString(OldValue, 10) << toString(Value, 10) << Param->getType()
6942 << Arg->getSourceRange();
6947 QualType T = ParamType->isEnumeralType() ? ParamType : IntegerType;
6954 QualType ArgType = Arg->getType();
6957 // Handle pointer-to-function, reference-to-function, and
6958 // pointer-to-member-function all in (roughly) the same way.
6959 if (// -- For a non-type template-parameter of type pointer to
6960 // function, only the function-to-pointer conversion (4.3) is
6961 // applied. If the template-argument represents a set of
6964 (ParamType->isPointerType() &&
6965 ParamType->castAs<PointerType>()->getPointeeType()->isFunctionType()) ||
6966 // -- For a non-type template-parameter of type reference to
6967 // function, no conversions apply. If the template-argument
6970 (ParamType->isReferenceType() &&
6971 ParamType->castAs<ReferenceType>()->getPointeeType()->isFunctionType()) ||
6972 // -- For a non-type template-parameter of type pointer to
6974 // template-argument represents a set of overloaded member
6977 (ParamType->isMemberPointerType() &&
6978 ParamType->castAs<MemberPointerType>()->getPointeeType()
6979 ->isFunctionType())) {
6981 if (Arg->getType() == Context.OverloadTy) {
6985 if (DiagnoseUseOfDecl(Fn, Arg->getBeginLoc()))
6992 ArgType = Arg->getType();
6997 if (!ParamType->isMemberPointerType()) {
7011 if (ParamType->isPointerType()) {
7012 // -- for a non-type template-parameter of type pointer to
7014 // array-to-pointer conversion (4.2) are applied.
7016 assert(ParamType->getPointeeType()->isIncompleteOrObjectType() &&
7025 if (const ReferenceType *ParamRefType = ParamType->getAs<ReferenceType>()) {
7026 // -- For a non-type template-parameter of type reference to
7028 // reference may be more cv-qualified than the (otherwise
7029 // identical) type of the template-argument. The
7030 // template-parameter is bound directly to the
7031 // template-argument, which must be an lvalue.
7032 assert(ParamRefType->getPointeeType()->isIncompleteOrObjectType() &&
7035 if (Arg->getType() == Context.OverloadTy) {
7037 ParamRefType->getPointeeType(),
7040 if (DiagnoseUseOfDecl(Fn, Arg->getBeginLoc()))
7046 ArgType = Arg->getType();
7058 if (ParamType->isNullPtrType()) {
7059 if (Arg->isTypeDependent() || Arg->isValueDependent()) {
7068 Diag(Arg->getExprLoc(), diag::err_template_arg_not_convertible)
7069 << Arg->getType() << ParamType;
7077 Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
7086 // -- For a non-type template-parameter of type pointer to data
7088 assert(ParamType->isMemberPointerType() && "Only pointers to members remain");
7108 assert(Name.isDependent() && "Non-dependent template isn't a declaration?");
7112 if (Template->isInvalidDecl())
7116 // A template-argument for a template template-parameter shall be
7118 // id-expression. When the template-argument names a class template, only
7134 Diag(Template->getLocation(), diag::note_template_arg_refers_here_func)
7139 // A template-argument matches a template template-parameter P when P
7140 // is at least as specialized as the template-argument A.
7145 // the template-parameter-list of P.
7147 Template->getTemplateParameters(), Params, false,
7151 // Otherwise - we need a more thorough check.
7152 !Template->hasAssociatedConstraints())
7162 Params->getAssociatedConstraints(ParamsAC);
7169 Template->getAssociatedConstraints(TemplateAC);
7179 Diag(Param->getLocation(), diag::note_entity_declared_at) << Param;
7180 Diag(Template->getLocation(), diag::note_entity_declared_at)
7191 return !TemplateParameterListsAreEqual(Template->getTemplateParameters(),
7217 if (ParamRange && ParamRange->isValid()) {
7234 // A non-type template-parameter of type "array of T" or
7237 if (ParamType->isArrayType())
7239 else if (ParamType->isFunctionType())
7242 // For a NULL non-type template argument, return nullptr casted to the
7248 ParamType->getAs<MemberPointerType>()
7258 if (ParamType->isMemberPointerType()) {
7260 // form a suitable pointer-to-member constant.
7261 assert(VD->getDeclContext()->isRecord() &&
7265 = Context.getTypeDeclType(cast<RecordDecl>(VD->getDeclContext()));
7273 SS, DeclarationNameInfo(VD->getDeclName(), Loc), VD);
7278 QualType ElemT(RefExpr.get()->getType()->getArrayElementTypeNoTypeQual(), 0);
7279 if (ParamType->isPointerType() && !ElemT.isNull() &&
7280 Context.hasSimilarType(ElemT, ParamType->getPointeeType())) {
7285 } else if (ParamType->isPointerType() || ParamType->isMemberPointerType()) {
7286 // For any other pointer, take the address (or form a pointer-to-member).
7290 } else if (ParamType->isRecordType()) {
7296 assert(ParamType->isReferenceType() &&
7300 QualType TemplateParamType = NTTP->getType();
7301 const AutoType *AT = TemplateParamType->getAs<AutoType>();
7302 if (AT && AT->isDecltypeAuto()) {
7304 ParamType->getPointeeType(), RefExpr.get()->getValueKind(),
7305 RefExpr.get()->getExprLoc(), RefExpr.get(), VD, NTTP->getIndex(),
7313 assert(ParamType->isReferenceType() == RefExpr.get()->isLValue() &&
7314 "value kind mismatch for non-type template argument");
7319 if (!Context.hasSameType(RefExpr.get()->getType(), DestExprType)) {
7322 if (Context.hasSimilarType(RefExpr.get()->getType(), DestExprType) ||
7323 IsFunctionConversion(RefExpr.get()->getType(), DestExprType, Ignored)) {
7325 } else if (ParamType->isVoidPointerType() &&
7326 RefExpr.get()->getType()->isPointerType()) {
7329 // FIXME: Pointers to members can need conversion derived-to-base or
7330 // base-to-derived conversions. We currently don't retain enough
7334 "unexpected conversion required for non-type template argument");
7337 RefExpr.get()->getValueKind());
7344 /// integral template argument with the given source-location
7352 assert(OrigT->isIntegralOrEnumerationType());
7360 if (const EnumType *ET = OrigT->getAs<EnumType>())
7361 T = ET->getDecl()->getIntegerType();
7364 if (T->isAnyCharacterType()) {
7366 if (T->isWideCharType())
7368 else if (T->isChar8Type() && S.getLangOpts().Char8)
7370 else if (T->isChar16Type())
7372 else if (T->isChar32Type())
7378 } else if (T->isBooleanType()) {
7384 if (OrigT->isEnumeralType()) {
7386 // non-type template parameters.
7398 auto MakeInitList = [&](ArrayRef<Expr *> Elts) -> Expr * {
7400 ILE->setType(T);
7428 QualType ElemT = T->castAs<ComplexType>()->getElementType();
7436 QualType ElemT = T->castAs<ComplexType>()->getElementType();
7445 QualType ElemT = T->castAs<VectorType>()->getElementType();
7458 // There isn't necessarily a valid equivalent source-level syntax for
7464 if (T->isReferenceType()) {
7465 T = T->getPointeeType();
7483 llvm_unreachable("not a non-type template argument");
7510 // Check the actual kind (type, non-type, template).
7511 if (Old->getKind() != New->getKind()) {
7518 S.Diag(New->getLocation(), NextDiag)
7520 S.Diag(Old->getLocation(), diag::note_template_prev_declaration)
7531 if (Old->isTemplateParameterPack() != New->isTemplateParameterPack() &&
7533 Old->isTemplateParameterPack())) {
7545 S.Diag(New->getLocation(), NextDiag)
7546 << ParamKind << New->isParameterPack();
7547 S.Diag(Old->getLocation(), diag::note_template_parameter_pack_here)
7548 << ParamKind << Old->isParameterPack();
7554 // For non-type template parameters, check the type of the parameter.
7560 // template parameter and one of the non-type template parameter types
7564 (!OldNTTP->getType()->isDependentType() &&
7565 !NewNTTP->getType()->isDependentType())) {
7567 // Two [non-type] template-parameters are equivalent [if] they have
7568 // equivalent types ignoring the use of type-constraints for
7570 QualType OldType = S.Context.getUnconstrainedType(OldNTTP->getType());
7571 QualType NewType = S.Context.getUnconstrainedType(NewNTTP->getType());
7580 S.Diag(NewNTTP->getLocation(), NextDiag)
7581 << NewNTTP->getType()
7583 S.Diag(OldNTTP->getLocation(),
7585 << OldNTTP->getType();
7599 NewInstFrom, NewTTP->getTemplateParameters(), OldInstFrom,
7600 OldTTP->getTemplateParameters(), Complain,
7614 if (const auto *TC = cast<TemplateTypeParmDecl>(New)->getTypeConstraint())
7615 NewC = TC->getImmediatelyDeclaredConstraint();
7616 if (const auto *TC = cast<TemplateTypeParmDecl>(Old)->getTypeConstraint())
7617 OldC = TC->getImmediatelyDeclaredConstraint();
7620 ->getPlaceholderTypeConstraint())
7623 ->getPlaceholderTypeConstraint())
7629 S.Diag(NewC ? NewC->getBeginLoc() : New->getBeginLoc(),
7631 S.Diag(OldC ? OldC->getBeginLoc() : Old->getBeginLoc(),
7667 S.Diag(New->getTemplateLoc(), NextDiag)
7668 << (New->size() > Old->size())
7670 << SourceRange(New->getTemplateLoc(), New->getRAngleLoc());
7671 S.Diag(Old->getTemplateLoc(), diag::note_template_prev_declaration)
7673 << SourceRange(Old->getTemplateLoc(), Old->getRAngleLoc());
7680 if (Old->size() != New->size() && Kind != TPL_TemplateTemplateArgumentMatch) {
7689 // A template-argument matches a template template-parameter (call it P)
7690 // when each of the template parameters in the template-parameter-list of
7691 // the template-argument's corresponding class template or alias template
7693 // template-parameter-list of P. [...]
7694 TemplateParameterList::iterator NewParm = New->begin();
7695 TemplateParameterList::iterator NewParmEnd = New->end();
7696 for (TemplateParameterList::iterator OldParm = Old->begin(),
7697 OldParmEnd = Old->end();
7700 !(*OldParm)->isTemplateParameterPack()) {
7719 // [...] When P's template- parameter-list contains a template parameter
7722 // template-parameter-list of A with the same type and form as the
7744 const Expr *NewRC = New->getRequiresClause();
7745 const Expr *OldRC = Old->getRequiresClause();
7748 Diag(NewRC ? NewRC->getBeginLoc() : New->getTemplateLoc(),
7750 Diag(OldRC ? OldRC->getBeginLoc() : Old->getTemplateLoc(),
7779 S = S->getDeclParent();
7784 DeclContext *Ctx = S->getEntity();
7785 if (Ctx && Ctx->isExternCContext()) {
7786 Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
7787 << TemplateParams->getSourceRange();
7788 if (const LinkageSpecDecl *LSD = Ctx->getExternCContext())
7789 Diag(LSD->getExternLoc(), diag::note_extern_c_begins_here);
7792 Ctx = Ctx ? Ctx->getRedeclContext() : nullptr;
7795 // A template-declaration can appear only as a namespace scope or
7804 if (Ctx->isFileContext())
7809 if (RD->isLocalClass())
7810 return Diag(TemplateParams->getTemplateLoc(),
7812 << TemplateParams->getSourceRange();
7818 return Diag(TemplateParams->getTemplateLoc(),
7820 << TemplateParams->getSourceRange();
7825 static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D) {
7826 if (!D)
7829 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D))
7830 return Record->getTemplateSpecializationKind();
7831 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D))
7832 return Function->getTemplateSpecializationKind();
7833 if (VarDecl *Var = dyn_cast<VarDecl>(D))
7834 return Var->getTemplateSpecializationKind();
7839 /// Check whether a specialization is well-formed in the current
7888 S.Diag(Specialized->getLocation(), diag::note_specialized_entity);
7895 if (S.CurContext->getRedeclContext()->isFunctionOrMethod()) {
7905 Specialized->getDeclContext()->getRedeclContext();
7906 DeclContext *DC = S.CurContext->getRedeclContext();
7910 if (!(DC->isFileContext() ? DC->Encloses(SpecializedContext)
7911 : DC->Equals(SpecializedContext))) {
7918 if (S.getLangOpts().MicrosoftExt && !DC->isRecord())
7924 S.Diag(Specialized->getLocation(), diag::note_specialized_entity);
7928 if (DC->isRecord())
7936 if (!E->isTypeDependent())
7941 return E->getSourceRange();
7946 if (!TL.getType()->isDependentType())
7956 /// that checks non-type template partial specialization arguments.
7977 ArgExpr = Expansion->getPattern();
7981 ArgExpr = ICE->getSubExpr();
7984 // A non-type argument is non-specialized if it is the name of a
7985 // non-type parameter. All other non-type arguments are
7989 // specialized non-type arguments, so skip any non-specialized
7992 if (isa<NonTypeTemplateParmDecl>(DRE->getDecl()))
7998 // -- A partially specialized non-type argument expression
8002 // -- The type of a template parameter corresponding to a
8003 // specialized non-type argument shall not be dependent on a
8007 // -- A specialized non-type template argument shall not be
8008 // type-dependent and the corresponding template parameter
8009 // shall have a non-dependent type.
8011 findTemplateParameterInType(Param->getDepth(), ArgExpr);
8028 Param->getDepth(), Param->getTypeSourceInfo()->getTypeLoc());
8030 S.Diag(IsDefaultArgument ? TemplateNameLoc : ArgExpr->getBeginLoc(),
8032 << Param->getType();
8046 if (PrimaryTemplate->getDeclContext()->isDependentContext())
8050 PrimaryTemplate->getTemplateParameters();
8051 for (unsigned I = 0, N = TemplateParams->size(); I != N; ++I) {
8053 = dyn_cast<NonTypeTemplateParmDecl>(TemplateParams->getParam(I));
8094 diagnoseQualifiedDeclaration(SS, ClassTemplate->getDeclContext(),
8095 ClassTemplate->getDeclName(),
8117 if (TemplateParams && TemplateParams->size() > 0) {
8129 for (unsigned I = 0, N = TemplateParams->size(); I != N; ++I) {
8130 Decl *Param = TemplateParams->getParam(I);
8132 if (TTP->hasDefaultArgument()) {
8133 Diag(TTP->getDefaultArgumentLoc(),
8135 TTP->removeDefaultArgument();
8139 if (NTTP->hasDefaultArgument()) {
8140 Diag(NTTP->getDefaultArgumentLoc(),
8142 << NTTP->getDefaultArgument().getSourceRange();
8143 NTTP->removeDefaultArgument();
8147 if (TTP->hasDefaultArgument()) {
8148 Diag(TTP->getDefaultArgument().getLocation(),
8150 << TTP->getDefaultArgument().getSourceRange();
8151 TTP->removeDefaultArgument();
8159 SourceRange(TemplateParams->getTemplateLoc(),
8160 TemplateParams->getRAngleLoc()))
8172 if (!isAcceptableTagRedeclaration(ClassTemplate->getTemplatedDecl(), Kind,
8174 ClassTemplate->getIdentifier())) {
8178 ClassTemplate->getTemplatedDecl()->getKindName());
8179 Diag(ClassTemplate->getTemplatedDecl()->getLocation(),
8181 Kind = ClassTemplate->getTemplatedDecl()->getTagKind();
8196 // Check that the template argument list is well-formed for this
8218 << ClassTemplate->getDeclName();
8228 PrevDecl = ClassTemplate->findPartialSpecialization(
8231 PrevDecl = ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
8253 ClassTemplate->getInjectedClassNameSpecialization()) &&
8255 !TemplateParams->hasAssociatedConstraints())) {
8258 // -- The argument list of the specialization shall not be identical
8267 ClassTemplate->getIdentifier(),
8273 TemplateParameterLists.size() - 1,
8282 Context, Kind, ClassTemplate->getDeclContext(), KWLoc,
8285 Partial->setTemplateArgsAsWritten(TemplateArgs);
8288 Partial->setTemplateParameterListsInfo(
8293 ClassTemplate->AddPartialSpecialization(Partial, InsertPos);
8298 if (PrevPartial && PrevPartial->getInstantiatedFromMember())
8299 PrevPartial->setMemberSpecialization();
8306 Context, Kind, ClassTemplate->getDeclContext(), KWLoc, TemplateNameLoc,
8308 Specialization->setTemplateArgsAsWritten(TemplateArgs);
8311 Specialization->setTemplateParameterListsInfo(Context,
8316 ClassTemplate->AddSpecialization(Specialization, InsertPos);
8318 if (CurContext->isDependentContext()) {
8333 if (PrevDecl && PrevDecl->getPointOfInstantiation().isValid()) {
8335 for (Decl *Prev = PrevDecl; Prev; Prev = Prev->getPreviousDecl()) {
8348 Diag(PrevDecl->getPointOfInstantiation(),
8350 << (PrevDecl->getTemplateSpecializationKind()
8358 Specialization->setSpecializationKind(TSK_ExplicitSpecialization);
8362 RecordDecl *Def = Specialization->getDefinition();
8365 SkipBody->ShouldSkip = true;
8366 SkipBody->Previous = Def;
8371 Diag(Def->getLocation(), diag::note_previous_definition);
8372 Specialization->setInvalidDecl();
8382 if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) {
8388 Diag(Specialization->getLocation(), diag::err_module_private_specialization)
8400 Specialization->setLexicalDeclContext(CurContext);
8403 if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip))
8404 Specialization->startDefinition();
8407 // Build the fully-sugared type for this class template
8409 // itself. This means that we'll pretty-print the type retrieved
8420 Friend->setAccess(AS_public);
8421 CurContext->addDecl(Friend);
8426 CurContext->addDecl(Specialization);
8429 if (SkipBody && SkipBody->ShouldSkip)
8430 return SkipBody->Previous;
8432 Specialization->setInvalidDecl(Invalid);
8438 Declarator &D) {
8439 Decl *NewDecl = HandleDeclarator(S, D, TemplateParameterLists);
8450 if (!DC->getRedeclContext()->isFileContext()) {
8463 if (Params->size() == 0) {
8470 for (TemplateParameterList::const_iterator ParamIt = Params->begin(),
8471 ParamEnd = Params->end();
8474 if (Param->isParameterPack()) {
8477 Diag(Param->getLocation(),
8489 if (NewDecl->hasAssociatedConstraints()) {
8493 NewDecl->setInvalidDecl();
8497 DeclarationNameInfo NameInfo(NewDecl->getDeclName(), NameLoc);
8522 auto *OldConcept = dyn_cast<ConceptDecl>(Previous.getRepresentativeDecl()->getUnderlyingDecl());
8525 Diag(NewDecl->getLocation(), diag::err_redefinition_different_kind)
8526 << NewDecl->getDeclName();
8527 notePreviousDefinition(Old, NewDecl->getLocation());
8534 Diag(NewDecl->getLocation(), diag::err_redefinition_different_concept)
8535 << NewDecl->getDeclName();
8536 notePreviousDefinition(OldConcept, NewDecl->getLocation());
8542 Diag(NewDecl->getLocation(), diag::err_redefinition)
8543 << NewDecl->getDeclName();
8544 notePreviousDefinition(OldConcept, NewDecl->getLocation());
8554 Context.setPrimaryMergedDecl(NewDecl, OldConcept->getCanonicalDecl());
8559 static void StripImplicitInstantiation(NamedDecl *D, bool MinGW) {
8560 if (MinGW || (isa<FunctionDecl>(D) &&
8561 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization()))
8562 D->dropAttrs<DLLImportAttr, DLLExportAttr>();
8564 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
8565 FD->setInlineSpecified(false);
8571 NamedDecl* D, SourceLocation PointOfInstantiation) {
8576 for (Decl *Prev = D; Prev && !PrevDiagLoc.isValid();
8577 Prev = Prev->getPreviousDecl()) {
8578 PrevDiagLoc = Prev->getLocation();
8635 for (Decl *Prev = PrevDecl; Prev; Prev = Prev->getPreviousDecl()) {
8706 Diag(PrevDecl->getLocation(),
8720 for (Decl *Prev = PrevDecl; Prev; Prev = Prev->getPreviousDecl()) {
8732 // For a given template and a given set of template-arguments,
8733 // - an explicit instantiation definition shall appear at most once
8756 DeclContext *FDLookupContext = FD->getDeclContext()->getRedeclContext();
8761 NamedDecl *D = F.next()->getUnderlyingDecl();
8762 if (!isa<FunctionTemplateDecl>(D)) {
8764 DiscardedCandidates.push_back(std::make_pair(NotAFunctionTemplate, D));
8768 if (!FDLookupContext->InEnclosingNamespaceSetOf(
8769 D->getDeclContext()->getRedeclContext())) {
8771 DiscardedCandidates.push_back(std::make_pair(NotAMemberOfEnclosing, D));
8777 bool IsFriend = FD->getFriendObjectKind() != Decl::FOK_None;
8779 Diag(FD->getLocation(), diag::err_dependent_function_template_spec_no_match)
8782 Diag(P.second->getLocation(),
8788 FD->setDependentTemplateSpecialization(Context, Previous.asUnresolvedSet(),
8799 TemplateSpecCandidateSet FailedCandidates(FD->getLocation(),
8805 DeclContext *FDLookupContext = FD->getDeclContext()->getRedeclContext();
8808 NamedDecl *Ovl = (*I)->getUnderlyingDecl();
8812 if (!FDLookupContext->InEnclosingNamespaceSetOf(
8813 Ovl->getDeclContext()->getRedeclContext()))
8816 QualType FT = FD->getType();
8818 // A constexpr specifier for a non-static member function that is not
8827 !getLangOpts().CPlusPlus14 && NewMD && NewMD->isConstexpr() &&
8829 auto *OldMD = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
8830 if (OldMD && OldMD->isConst()) {
8831 const FunctionProtoType *FPT = FT->castAs<FunctionProtoType>();
8832 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
8834 FT = Context.getFunctionType(FPT->getReturnType(),
8835 FPT->getParamTypes(), EPI);
8844 // A trailing template-argument can be left unspecified in the
8845 // template-id naming an explicit function template specialization
8853 cast<FunctionTemplateDecl>(FunTmpl->getFirstDecl()),
8859 I.getPair(), FunTmpl->getTemplatedDecl(),
8875 I.getPair(), FunTmpl->getTemplatedDecl(),
8890 // non-template) candidates.
8892 Diag(FD->getLocation(), diag::err_qualified_friend_no_match)
8893 << FD->getDeclName() << FDLookupContext;
8897 if (auto *OldFD = dyn_cast<FunctionDecl>(OldND->getUnderlyingDecl()))
8898 NoteOverloadCandidate(OldND, OldFD, CRK_None, FD->getType(), false);
8900 FailedCandidates.NoteCandidates(*this, FD->getLocation());
8906 Candidates.begin(), Candidates.end(), FailedCandidates, FD->getLocation(),
8907 PDiag(diag::err_function_template_spec_no_match) << FD->getDeclName(),
8909 << FD->getDeclName() << (ExplicitTemplateArgs != nullptr),
8920 // - [...]
8921 // - the exception specification is compared to that of another declaration
8923 // - [...]
8926 // described above only when needed; similarly, the noexcept-specifier of a
8944 Specialization->getType()->castAs<FunctionProtoType>();
8948 isUnresolvedExceptionSpec(SpecializationFPT->getExceptionSpecType()) &&
8949 !ResolveExceptionSpec(FD->getLocation(), SpecializationFPT))
8953 = Specialization->getTemplateSpecializationInfo();
8958 TemplateSpecializationKind TSK = SpecInfo->getTemplateSpecializationKind();
8960 Specialization->setLocation(FD->getLocation());
8961 Specialization->setLexicalDeclContext(FD->getLexicalDeclContext());
8968 Specialization->setConstexprKind(FD->getConstexprKind());
8976 bool isFriend = (FD->getFriendObjectKind() != Decl::FOK_None);
8981 Specialization->getPrimaryTemplate(),
8982 Specialization, FD->getLocation(),
8994 CheckSpecializationInstantiationRedecl(FD->getLocation(),
8997 SpecInfo->getTemplateSpecializationKind(),
8998 SpecInfo->getPointOfInstantiation(),
9006 // primary function template - check if the 'specialization' that was
9012 // flag to not-deleted, so that we can inherit that information from 'FD'.
9013 if (Specialization->isDeleted() && !SpecInfo->isExplicitSpecialization() &&
9014 !Specialization->getCanonicalDecl()->isReferenced()) {
9017 Specialization->getCanonicalDecl() == Specialization &&
9020 Specialization->setDeletedAsWritten(false);
9023 SpecInfo->setTemplateSpecializationKind(TSK_ExplicitSpecialization);
9032 Context, Specialization->getTemplateSpecializationArgs()->asArray());
9033 FD->setFunctionTemplateSpecialization(
9034 Specialization->getPrimaryTemplate(), TemplArgs, /*InsertPos=*/nullptr,
9035 SpecInfo->getTemplateSpecializationKind(),
9044 CUDA().inheritTargetAttrs(FD, *Specialization->getPrimaryTemplate());
9055 assert(!isa<TemplateDecl>(Member) && "Only for non-template members");
9071 dyn_cast<CXXMethodDecl>((*I)->getUnderlyingDecl());
9074 QualType Adjusted = Function->getType();
9076 Adjusted = adjustCCAndNoReturn(Adjusted, Method->getType());
9079 if (!Context.hasSameType(Adjusted, Method->getType()))
9082 Method->getTrailingRequiresClause() &&
9084 /*UsageLoc=*/Member->getLocation(),
9101 InstantiatedFrom = Method->getInstantiatedFromMemberFunction();
9102 MSInfo = Method->getMemberSpecializationInfo();
9106 Diag(Member->getLocation(), diag::err_function_member_spec_ambiguous)
9109 Diag(Candidate->getLocation(), diag::note_function_member_spec_matched)
9117 if (PrevVar->isStaticDataMember()) {
9120 InstantiatedFrom = PrevVar->getInstantiatedFromStaticDataMember();
9121 MSInfo = PrevVar->getMemberSpecializationInfo();
9129 InstantiatedFrom = PrevRecord->getInstantiatedFromMemberClass();
9130 MSInfo = PrevRecord->getMemberSpecializationInfo();
9138 InstantiatedFrom = PrevEnum->getInstantiatedFromMemberEnum();
9139 MSInfo = PrevEnum->getMemberSpecializationInfo();
9145 // specializations are always out-of-line, the caller will complain about
9155 if (Member->getFriendObjectKind() != Decl::FOK_None) {
9158 cast<CXXMethodDecl>(Member)->setInstantiationOfMemberFunction(
9160 cast<CXXMethodDecl>(Instantiation)->getTemplateSpecializationKind());
9162 cast<CXXRecordDecl>(Member)->setInstantiationOfMemberClass(
9164 cast<CXXRecordDecl>(Instantiation)->getTemplateSpecializationKind());
9174 Diag(Member->getLocation(), diag::err_spec_member_not_instantiated)
9176 Diag(Instantiation->getLocation(), diag::note_specialized_decl);
9189 if (CheckSpecializationInstantiationRedecl(Member->getLocation(),
9192 MSInfo->getTemplateSpecializationKind(),
9193 MSInfo->getPointOfInstantiation(),
9200 Instantiation, Member->getLocation(),
9208 if (InstantiationFunction->getTemplateSpecializationKind() ==
9212 if (InstantiationFunction->isDeleted()) {
9214 assert(InstantiationFunction->getCanonicalDecl() ==
9217 InstantiationFunction->setDeletedAsWritten(false);
9221 MemberFunction->setInstantiationOfMemberFunction(
9224 MemberVar->setInstantiationOfStaticDataMember(
9227 MemberClass->setInstantiationOfMemberClass(
9230 MemberEnum->setInstantiationOfMemberEnum(
9251 if (OrigD->getTemplateSpecializationKind() != TSK_ImplicitInstantiation)
9255 // FIXME: If there are multiple in-class declarations of the member (from
9258 OrigD->setTemplateSpecializationKind(TSK_ExplicitSpecialization);
9259 OrigD->setLocation(Loc);
9264 NamedDecl *Instantiation = cast<NamedDecl>(Member->getCanonicalDecl());
9269 completeMemberSpecializationImpl(*this, Function, Member->getLocation());
9271 completeMemberSpecializationImpl(*this, Var, Member->getLocation());
9273 completeMemberSpecializationImpl(*this, Record, Member->getLocation());
9275 completeMemberSpecializationImpl(*this, Enum, Member->getLocation());
9283 static bool CheckExplicitInstantiationScope(Sema &S, NamedDecl *D,
9286 DeclContext *OrigContext= D->getDeclContext()->getEnclosingNamespaceContext();
9287 DeclContext *CurContext = S.CurContext->getRedeclContext();
9289 if (CurContext->isRecord()) {
9291 << D;
9304 if (CurContext->Encloses(OrigContext))
9307 if (CurContext->InEnclosingNamespaceSetOf(OrigContext))
9317 << D << NS;
9323 << D << NS;
9329 << D;
9330 S.Diag(D->getLocation(), diag::note_explicit_instantiation_here);
9334 /// Common checks for whether an explicit instantiation of \p D is valid.
9335 static bool CheckExplicitInstantiation(Sema &S, NamedDecl *D,
9343 D->getFormalLinkage() == Linkage::Internal) {
9344 S.Diag(InstLoc, diag::err_explicit_instantiation_internal_linkage) << D;
9351 if (CheckExplicitInstantiationScope(S, D, InstLoc, WasQualifiedName))
9357 /// Determine whether the given scope specifier has a template-id in it.
9365 // the class template specialization in the qualified-id for the member
9366 // name shall be a simple-template-id.
9370 NNS = NNS->getPrefix())
9371 if (const Type *T = NNS->getAsType())
9393 for (auto &B : Def->bases()) {
9395 B.getType()->getAsCXXRecordDecl()))
9423 Diag(TD->getLocation(), diag::note_previous_use);
9427 if (!isAcceptableTagRedeclaration(ClassTemplate->getTemplatedDecl(),
9429 ClassTemplate->getIdentifier())) {
9433 ClassTemplate->getTemplatedDecl()->getKindName());
9434 Diag(ClassTemplate->getTemplatedDecl()->getLocation(),
9436 Kind = ClassTemplate->getTemplatedDecl()->getTagKind();
9460 if (auto *A = ClassTemplate->getTemplatedDecl()->getAttr<DLLExportAttr>()) {
9463 Diag(A->getLocation(), diag::note_attribute);
9474 ClassTemplate->getTemplatedDecl()->getAttr<DLLImportAttr>();
9494 // Check that the template argument list is well-formed for this
9506 ClassTemplate->findSpecialization(CanonicalConverted, InsertPos);
9509 = PrevDecl ? PrevDecl->getTemplateSpecializationKind() : TSK_Undeclared;
9534 PrevDecl->getPointOfInstantiation(),
9549 Specialization->setLocation(TemplateNameLoc);
9564 Context, Kind, ClassTemplate->getDeclContext(), KWLoc, TemplateNameLoc,
9571 if (const auto *A = PrevDecl->getAttr<MSInheritanceAttr>()) {
9572 auto *Clone = A->clone(getASTContext());
9573 Clone->setInherited(true);
9574 Specialization->addAttr(Clone);
9581 ClassTemplate->AddSpecialization(Specialization, InsertPos);
9585 Specialization->setTemplateArgsAsWritten(TemplateArgs);
9588 Specialization->setExternKeywordLoc(ExternLoc);
9589 Specialization->setTemplateKeywordLoc(TemplateLoc);
9590 Specialization->setBraceRange(SourceRange());
9592 bool PreviouslyDLLExported = Specialization->hasAttr<DLLExportAttr>();
9599 Specialization->setLexicalDeclContext(CurContext);
9600 CurContext->addDecl(Specialization);
9605 Specialization->setTemplateSpecializationKind(TSK);
9618 Specialization->getDefinition());
9623 Specialization->setPointOfInstantiation(Def->getPointOfInstantiation());
9628 Specialization->getDefinition());
9630 TemplateSpecializationKind Old_TSK = Def->getTemplateSpecializationKind();
9637 Def->setTemplateSpecializationKind(TSK);
9645 getDLLAttr(Specialization)->clone(getASTContext()));
9646 A->setInherited(true);
9647 Def->addAttr(A);
9655 !PreviouslyDLLExported && Specialization->hasAttr<DLLExportAttr>();
9679 PrevDecl->hasAttr<DLLExportAttr>()) {
9685 Specialization->setTemplateSpecializationKind(TSK);
9690 Specialization->setTemplateSpecializationKind(TSK);
9718 assert(!Tag->isEnum() && "shouldn't see enumerations here");
9720 if (Tag->isInvalidDecl())
9724 CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
9728 Diag(Record->getLocation(), diag::note_nontemplate_decl_here);
9734 // elaborated-type-specifier in the declaration shall include a
9735 // simple-template-id.
9754 = cast_or_null<CXXRecordDecl>(Record->getPreviousDecl());
9755 if (!PrevDecl && Record->getDefinition())
9758 MemberSpecializationInfo *MSInfo = PrevDecl->getMemberSpecializationInfo();
9763 MSInfo->getTemplateSpecializationKind(),
9764 MSInfo->getPointOfInstantiation(),
9772 = cast_or_null<CXXRecordDecl>(Record->getDefinition());
9778 = cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
9781 << 0 << Record->getDeclName() << Record->getDeclContext();
9782 Diag(Pattern->getLocation(), diag::note_forward_declaration)
9791 RecordDef = cast_or_null<CXXRecordDecl>(Record->getDefinition());
9814 Declarator &D) {
9817 DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
9820 if (!D.isInvalidType())
9821 Diag(D.getDeclSpec().getBeginLoc(),
9823 << D.getDeclSpec().getSourceRange() << D.getSourceRange();
9829 S = S->getDeclParent();
9832 TypeSourceInfo *T = GetTypeForDeclarator(D);
9833 QualType R = T->getType();
9838 // A storage-class-specifier shall not be specified in [...] an explicit
9840 if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
9841 Diag(D.getIdentifierLoc(), diag::err_explicit_instantiation_of_typedef)
9844 } else if (D.getDeclSpec().getStorageClassSpec()
9847 Diag(D.getIdentifierLoc(), diag::err_explicit_instantiation_storage_class)
9848 << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc());
9850 D.getMutableDeclSpec().ClearStorageClassSpecs();
9858 if (D.getDeclSpec().isInlineSpecified())
9859 Diag(D.getDeclSpec().getInlineSpecLoc(),
9863 << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc());
9864 if (D.getDeclSpec().hasConstexprSpecifier() && R->isFunctionType())
9865 // FIXME: Add a fix-it to remove the 'constexpr' and add a 'const' if one is
9867 Diag(D.getDeclSpec().getConstexprSpecLoc(),
9873 Diag(D.getDeclSpec().getBeginLoc(), diag::err_deduction_guide_specialized)
9887 LookupParsedName(Previous, S, &D.getCXXScopeSpec(),
9890 if (!R->isFunctionType()) {
9905 if (!Prev || !Prev->isStaticDataMember()) {
9907 Diag(D.getIdentifierLoc(), diag::err_explicit_instantiation_not_known)
9911 Diag((*P)->getLocation(), diag::note_explicit_instantiation_here);
9915 if (!Prev->getInstantiatedFromStaticDataMember()) {
9917 Diag(D.getIdentifierLoc(),
9920 Diag(Prev->getLocation(), diag::note_explicit_instantiation_here);
9929 // explicitly allowed in this section is ill-formed.
9931 // This includes auto-typed variable template instantiations.
9932 if (R->isUndeducedType()) {
9933 Diag(T->getTypeLoc().getBeginLoc(),
9938 if (D.getName().getKind() != UnqualifiedIdKind::IK_TemplateId) {
9940 // If the explicit instantiation is for a variable, the unqualified-id
9941 // in the declaration shall be a template-id.
9942 Diag(D.getIdentifierLoc(),
9945 Diag(PrevTemplate->getLocation(),
9952 makeTemplateArgumentListInfo(*this, *D.getName().TemplateId);
9955 D.getIdentifierLoc(), TemplateArgs);
9963 Diag(D.getIdentifierLoc(), diag::err_explicit_instantiation_dependent);
9975 // the class template specialization in the qualified-id for the member
9976 // name shall be a simple-template-id.
9981 // template-id is in the unqualified-id instead.
9982 if (!ScopeSpecifierHasTemplateId(D.getCXXScopeSpec()) && !PrevTemplate)
9983 Diag(D.getIdentifierLoc(),
9985 << Prev << D.getCXXScopeSpec().getRange();
9987 CheckExplicitInstantiation(*this, Prev, D.getIdentifierLoc(), true, TSK);
9990 TemplateSpecializationKind PrevTSK = Prev->getTemplateSpecializationKind();
9991 SourceLocation POI = Prev->getPointOfInstantiation();
9993 if (CheckSpecializationInstantiationRedecl(D.getIdentifierLoc(), TSK, Prev,
9999 Prev->setTemplateSpecializationKind(TSK, D.getIdentifierLoc());
10001 VTSD->setExternKeywordLoc(ExternLoc);
10002 VTSD->setTemplateKeywordLoc(TemplateLoc);
10006 ProcessDeclAttributeList(S, Prev, D.getDeclSpec().getAttributes());
10011 InstantiateVariableDefinition(D.getIdentifierLoc(), Prev);
10015 if (PrevTemplate && !Context.hasSameType(Prev->getType(), R)) {
10016 Diag(T->getTypeLoc().getBeginLoc(),
10018 << 0 << PrevTemplate << R << Prev->getType();
10019 Diag(PrevTemplate->getLocation(), diag::note_template_declared_here)
10020 << 2 << PrevTemplate->getDeclName();
10028 // If the declarator is a template-id, translate the parser's template
10032 if (D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
10033 TemplateArgs = makeTemplateArgumentListInfo(*this, *D.getName().TemplateId);
10044 TemplateSpecCandidateSet FailedCandidates(D.getIdentifierLoc());
10050 QualType Adjusted = adjustCCAndNoReturn(R, Method->getType(),
10052 if (Context.hasSameUnqualifiedType(Method->getType(), Adjusted)) {
10053 if (Method->getPrimaryTemplate()) {
10074 // Keep track of almost-matches.
10076 .set(P.getPair(), FunTmpl->getTemplatedDecl(),
10090 CUDA().IdentifyTarget(D.getDeclSpec().getAttributes())) {
10092 P.getPair(), FunTmpl->getTemplatedDecl(),
10106 D.getIdentifierLoc(),
10119 // In an explicit instantiation an exception-specification may be specified,
10121 // If an exception-specification is specified in an explicit instantiation
10122 // directive, it shall be compatible with the exception-specifications of
10124 if (auto *FPT = R->getAs<FunctionProtoType>())
10125 if (FPT->hasExceptionSpec()) {
10131 PDiag(DiagID) << Specialization->getType(),
10133 Specialization->getType()->getAs<FunctionProtoType>(),
10134 Specialization->getLocation(), FPT, D.getBeginLoc());
10141 if (Specialization->getTemplateSpecializationKind() == TSK_Undeclared) {
10142 Diag(D.getIdentifierLoc(),
10145 << (Specialization->getTemplateSpecializationKind() ==
10147 Diag(Specialization->getLocation(), diag::note_explicit_instantiation_here);
10151 FunctionDecl *PrevDecl = Specialization->getPreviousDecl();
10152 if (!PrevDecl && Specialization->isThisDeclarationADefinition())
10157 if (CheckSpecializationInstantiationRedecl(D.getIdentifierLoc(), TSK,
10159 PrevDecl->getTemplateSpecializationKind(),
10160 PrevDecl->getPointOfInstantiation(),
10176 if (Specialization->hasAttr<InternalLinkageAttr>() &&
10178 if (auto *RD = dyn_cast<CXXRecordDecl>(Specialization->getDeclContext()))
10179 if (RD->getIdentifier() && RD->getIdentifier()->isStr("valarray") &&
10180 RD->isInStdNamespace())
10184 ProcessDeclAttributeList(S, Specialization, D.getDeclSpec().getAttributes());
10190 Specialization->hasAttr<DLLImportAttr>() &&
10194 Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc());
10196 if (Specialization->isDefined()) {
10201 InstantiateFunctionDefinition(D.getIdentifierLoc(), Specialization);
10206 // the class template specialization in the qualified-id for the member
10207 // name shall be a simple-template-id.
10210 FunctionTemplateDecl *FunTmpl = Specialization->getPrimaryTemplate();
10211 if (D.getName().getKind() != UnqualifiedIdKind::IK_TemplateId && !FunTmpl &&
10212 D.getCXXScopeSpec().isSet() &&
10213 !ScopeSpecifierHasTemplateId(D.getCXXScopeSpec()))
10214 Diag(D.getIdentifierLoc(),
10216 << Specialization << D.getCXXScopeSpec().getRange();
10221 : Specialization->getInstantiatedFromMemberFunction(),
10222 D.getIdentifierLoc(), D.getCXXScopeSpec().isSet(), TSK);
10253 // Create type-source location information for this type.
10254 TypeLocBuilder TLB;
10255 DependentNameTypeLoc TL = TLB.push<DependentNameTypeLoc>(Result);
10259 return CreateParsedType(Result, TLB.getTypeSourceInfo(Context, Result));
10270 if (TypenameLoc.isValid() && S && !S->getTemplateParamParent())
10298 if (TypenameLoc.isValid() && S && !S->getTemplateParamParent())
10305 // Strangely, non-type results are not ignored by this lookup, so the
10306 // program is ill-formed if it finds an injected-class-name.
10310 if (LookupRD && LookupRD->getIdentifier() == TemplateII) {
10313 << TemplateII << 0 /*injected-class-name used as template name*/
10325 assert(DTN && "dependent template has non-dependent name?");
10326 assert(DTN->getQualifier() == SS.getScopeRep());
10328 if (!DTN->isIdentifier()) {
10335 ElaboratedTypeKeyword::Typename, DTN->getQualifier(),
10336 DTN->getIdentifier(), TemplateArgs.arguments());
10338 // Create source-location information for this type.
10357 // Provide source-location information for the template specialization type.
10386 // ... within an explicitly-written template specialization...
10387 if (!NNS || !NNS.getNestedNameSpecifier()->getAsType())
10398 EnableIfTST->getTemplateName().getAsTemplateDecl();
10399 if (!EnableIfDecl || EnableIfTST->isIncompleteType())
10404 EnableIfDecl->getDeclName().getAsIdentifierInfo();
10405 if (!EnableIfII || !EnableIfII->isStr("enable_if"))
10420 if (isa<CXXBoolLiteralExpr>(Cond->IgnoreParenCasts()))
10442 (*TSI)->getTypeLoc().castAs<DependentNameTypeLoc>();
10447 ElaboratedTypeLoc TL = (*TSI)->getTypeLoc().castAs<ElaboratedTypeLoc>();
10470 // If the nested-name-specifier is dependent and couldn't be
10472 assert(QualifierLoc.getNestedNameSpecifier()->isDependent());
10478 // If the nested-name-specifier refers to the current instantiation,
10480 // program is actually ill-formed. However, DR 382 (in C++0x CD1)
10511 Diag(FailedCond->getExprLoc(),
10514 << FailedCond->getSourceRange();
10538 SourceLocation Loc = Using->getQualifierLoc().getBeginLoc();
10557 // nested-name-specifier nominates a class C, if the name specified
10558 // after the nested-name-specifier, when looked up in C, is the
10559 // injected-class-name of C [...] then the name is instead considered
10562 // Unlike in an elaborated-type-specifier, function names are not ignored
10563 // in typename-specifier lookup. However, they are ignored in all the
10565 // mem-initializer-ids, base-specifiers, and elaborated-type-specifiers).
10567 // FIXME: That's not strictly true: mem-initializer-id lookup does not
10572 FoundRD->isInjectedClassName() &&
10573 declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent())))
10578 // typename-specifier was just sugar.
10579 MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false);
10586 // A type-specifier of the form
10587 // typename[opt] nested-name-specifier[opt] template-name
10593 ? QualifierLoc.getNestedNameSpecifier()->getAsType()
10635 Diag(Referenced->getLocation(),
10664 return T.isNull() || !T->isInstantiationDependentType();
10674 /// Sets the "base" location and entity when that
10677 this->Loc = Loc;
10678 this->Entity = Entity;
10691 if (!T || !T->getType()->isInstantiationDependentType())
10699 CurrentInstantiationRebuilder Rebuilder(*this, E->getExprLoc(),
10722 for (unsigned I = 0, N = Params->size(); I != N; ++I) {
10723 Decl *Param = Params->getParam(I);
10733 TTP->getTemplateParameters()))
10739 // Rebuild the type of a non-type template parameter.
10742 = RebuildTypeInCurrentInstantiation(NTTP->getTypeSourceInfo(),
10743 NTTP->getLocation(),
10744 NTTP->getDeclName());
10748 if (NewTSI->getType()->isUndeducedType()) {
10750 // An id-expression is type-dependent if it contains
10751 // - an identifier associated by name lookup with a non-type
10752 // template-parameter declared with a type that contains a
10757 if (NewTSI != NTTP->getTypeSourceInfo()) {
10758 NTTP->setTypeSourceInfo(NewTSI);
10759 NTTP->setType(NewTSI->getType());
10779 if (!Params || Params->size() == 0 || NumArgs == 0)
10782 for (unsigned I = 0, N = Params->size(); I != N; ++I) {
10791 if (const IdentifierInfo *Id = Params->getParam(I)->getIdentifier()) {
10792 Out << Id->getName();
10815 LPT->Toks.swap(Toks);
10816 LPT->D = FnD;
10817 LPT->FPO = getCurFPFeatures();
10820 FD->setLateTemplateParsed(true);
10826 FD->setLateTemplateParsed(false);
10834 const FunctionDecl *FD = RD->isLocalClass();
10835 return (FD && FD->getTemplatedKind() != FunctionDecl::TK_NonTemplate);
10836 } else if (DC->isTranslationUnit() || DC->isNamespace())
10839 DC = DC->getParent();
10885 void diagnose(NamedDecl *D, bool IsPartialSpec) {
10894 S.diagnoseMissingImport(Loc, D, Kind, Recover);
10896 S.diagnoseMissingImport(Loc, D, D->getLocation(), Modules, Kind, Recover);
10899 bool CheckMemberSpecialization(const NamedDecl *D) {
10901 ? S.hasVisibleMemberSpecialization(D)
10902 : S.hasReachableMemberSpecialization(D);
10905 bool CheckExplicitSpecialization(const NamedDecl *D) {
10907 ? S.hasVisibleExplicitSpecialization(D)
10908 : S.hasReachableExplicitSpecialization(D);
10911 bool CheckDeclaration(const NamedDecl *D) {
10912 return Kind == Sema::AcceptableKind::Visible ? S.hasVisibleDeclaration(D)
10913 : S.hasReachableDeclaration(D);
10931 if (Spec->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
10932 IsHiddenExplicitSpecialization = Spec->getMemberSpecializationInfo()
10940 diagnose(Spec->getMostRecentDecl(), false);
10944 if (auto *TD = FD->getPrimaryTemplate())
10953 auto From = SD->getSpecializedTemplateOrPartial();
10969 auto From = SD->getSpecializedTemplateOrPartial();
10984 if (TD->isMemberSpecialization()) {
10986 diagnose(TD->getMostRecentDecl(), false);
11013 return N->getLocation();
11015 if (!FD->isFunctionTemplateSpecialization())
11016 return FD->getLocation();
11019 return N->getLocation();
11026 return N->getLocation();