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