Home | History | Annotate | Download | only in Sema

Lines Matching full:template

30 #include "clang/Sema/Template.h"
47 /// of a template and, if so, return that template declaration. Otherwise,
63 // Like normal (non-template) classes, class templates have an
65 // can be used with or without a template-argument-list. When
66 // it is used without a template-argument-list, it is
68 // template-parameters of the class template enclosed in
69 // <>. When it is used with a template-argument-list, it
70 // refers to the specified class template specialization,
106 // refer to specializations of the same class template, and if the name
107 // is used as a template-name, the reference refers to the class
108 // template itself and not a specialization thereof, and is not
118 // found this template through a particular injected class name,
144 assert(getLangOpts().CPlusPlus && "No template names in C!");
182 TemplateName Template;
188 // template name in other ways.
189 Template = Context.getOverloadedTemplateName(R.begin(), R.end());
199 Template = Context.getQualifiedTemplateName(Qualifier,
202 Template = TemplateName(TD);
219 TemplateResult = TemplateTy::make(Template);
230 // template name.
236 // The code is missing a 'template' keyword prior to the dependent template
241 << FixItHint::CreateInsertion(IILoc, "template ");
267 // Template names cannot appear inside an Objective-C class or object type.
296 // beginning of a template argument list (14.2) or a less-than operator.
300 // or function template.
363 // template, the name is also looked up in the context of the entire
378 // postfix-expression and does not name a class template, the name
382 // - if the name found is a class template, it must refer to the same
398 // Recover by taking the template that we found in the object
445 /// that the template parameter 'PrevDecl' is being shadowed by a new
449 assert(PrevDecl->isTemplateParameter() && "Not a template parameter");
451 // Microsoft Visual C++ permits template parameters to be shadowed.
456 // A template-parameter shall not be redeclared within its
464 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
466 /// to the template declaration. Otherwise, do nothing to D and return null.
477 assert(Kind == Template &&
478 "Only template template arguments can be pack expansions here");
480 "Template template argument pack expansion without packs");
503 case ParsedTemplateArgument::Template: {
504 TemplateName Template = Arg.getAsTemplate().get();
507 TArg = TemplateArgument(Template, Optional<unsigned int>());
509 TArg = Template;
518 llvm_unreachable("Unhandled parsed template argument");
521 /// \brief Translates template arguments as provided by the parser
522 /// into template arguments used by semantic analysis.
539 /// ActOnTypeParameter - Called when a C++ template type parameter
544 /// parameter (NULL indicates an unnamed template parameter) and
557 "Template type parameter not in template parameter scope!");
576 // Add the template parameter into the current scope.
582 // A default template-argument may be specified for any kind of
583 // template-parameter that is not a template parameter pack.
601 // Check the template argument itself.
613 /// \brief Check that the type of a non-type template parameter is
620 // We don't allow variably-modified types as the type of non-type template
630 // A non-type template-parameter shall have one of the following
646 // C++ [temp.param]p5: The top-level cv-qualifiers on the template-parameter
653 // A non-type template-parameter of type "array of T" or
674 "Non-type template parameter not in template parameter scope!");
700 // Add the template parameter into the current scope.
706 // A default template-argument may be specified for any kind of
707 // template-parameter that is not a template parameter pack.
713 // Check the well-formedness of the default template argument, if provided.
734 /// ActOnTemplateTemplateParameter - Called when a C++ template template
735 /// parameter (e.g. T in template <template \<typename> class T> class array)
748 "Template template parameter not in template parameter scope!");
759 // If the template template parameter has a name, then link the identifier
775 // A default template-argument may be specified for any kind of
776 // template-parameter that is not a template parameter pack.
783 // Check only that we have a template template argument. We don't want to
784 // try to check well-formedness now, because our template template parameter
785 // might have dependent types in its template parameters, which we wouldn't
788 // If none of the template template parameter's template arguments mention
789 // other template parameters, we could actually perform more checking here.
811 /// contains the template parameters in Params/NumParams.
844 "No template parameters");
848 // Check that we can declare a template here.
853 assert(Kind != TTK_Enum && "can't build template of enumerated type");
855 // There is no such thing as an unnamed class template.
885 // If we're adding a template to a dependent context, we may need to
886 // rebuilding some of the types used within the template parameter list,
902 // -- every member template of class T
923 // We may have found the injected-class-name of a class template,
924 // class template partial specialization, or class template specialization.
925 // In these cases, grab the template that is being defined or specialized.
942 // function is neither a qualified name nor a template-id, scopes outside
996 // Ensure that the template parameter lists are compatible. Skip this check
997 // for a friend in a dependent context: the template parameter list itself
1008 // specialization or explicit instantiation of a class template,
1010 // template declaration (7.1.5.3).
1021 // Check for redefinition of this class template.
1030 assert(Tmpl && "original definition of a class template is not a "
1031 "class template?");
1045 // Maybe we will complain about the shadowed template parameter.
1051 // A class template shall not have the same name as any other
1052 // template, class, function, object, enumeration, enumerator,
1060 // Check the template parameter list of this declaration, possibly
1061 // merging in the template parameter list from the previous class
1062 // template declaration. Skip this check for a friend in a dependent
1063 // context, because the template parameter list might be dependent.
1077 // If the name of the template was qualified, we must be defining the
1078 // template out-of-line.
1114 // Build the type for the class template declaration now.
1117 assert(T->isDependentType() && "Class template type is not dependent?");
1121 // class template, make a note of that.
1146 // Per C++ [basic.scope.temp]p2, skip the template parameter scopes.
1184 /// \brief Diagnose the presence of a default template argument on a
1185 /// template parameter, which is ill-formed in certain contexts.
1187 /// \returns true if the default template argument should be dropped.
1201 // A default template-argument shall not be specified in a
1202 // function template declaration or a function template
1204 // If a friend function template declaration specifies a default
1205 // template-argument, that declaration shall be a definition and shall be
1206 // the only declaration of the function template in the translation unit.
1216 // A default template-argument shall not be specified in the
1217 // template-parameter-lists of the definition of a member of a
1218 // class template that appears outside of the member's class.
1226 // A default template-argument shall not be specified in a
1227 // friend template declaration.
1232 // FIXME: C++0x [temp.param]p9 allows default template-arguments
1240 /// \brief Check for unexpanded parameter packs within the template parameters
1241 /// of a template template parameter, recursively.
1244 // A template template parameter which is a parameter pack is also a pack
1271 /// \brief Checks the validity of a template parameter list, possibly
1272 /// considering the template parameter list from a previous
1275 /// If an "old" template parameter list is provided, it must be
1277 /// template parameter list.
1279 /// \param NewParams Template parameter list for a new template
1280 /// declaration. This template parameter list will be updated with any
1282 /// template parameter list.
1284 /// \param OldParams If provided, template parameter list from a
1285 /// previous declaration of the same template. Default template
1286 /// arguments will be merged from the old template parameter list to
1287 /// the new template parameter list.
1290 /// template parameter list.
1299 // The set of default template-arguments available for use with a
1300 // template declaration or definition is obtained by merging the
1337 // Merge default arguments for template type parameters.
1380 // Merge default arguments for non-type template parameters
1422 // Merge default arguments for template template parameters
1453 // If a template parameter of a primary class template or alias template
1454 // is a template parameter pack, it shall be the last template parameter.
1465 // A template-parameter shall not be given default arguments
1472 // If a template-parameter of a class template has a default
1473 // template-argument, each subsequent template-parameter shall either
1474 // have a default template-argument supplied or be a template parameter
1483 // If we have an old template parameter list that we're merging
1510 /// A class which looks for a use of a certain level of template
1609 /// \brief Match the given template parameter lists to the given scope
1610 /// specifier, returning the template parameter list that applies to the
1614 template parameter list.
1618 /// \param SS the scope specifier that will be matched to the given template
1622 /// \param TemplateId The template-id following the scope specifier, if there
1623 /// is one. Used to check for a missing 'template<>'.
1625 /// \param ParamLists the template parameter lists, from the outermost to the
1626 /// innermost template parameter lists.
1629 /// matching template parameters to scope specifiers in friend
1635 /// \returns the template parameter list, if any, that corresponds to the
1636 /// name that is preceded by the scope specifier @p SS. This template
1637 /// parameter list may have template parameters (if we're declaring a
1638 /// template) or may have no template parameters (if we're declaring a
1639 /// template specialization), or may be NULL (if what we're declaring isn't
1640 /// itself a template).
1649 // The sequence of nested types to which we will match up the template
1663 // 'template<>' headers, this will be set to the location of that
1695 if (TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
1696 if (TypeDecl *Parent = dyn_cast<TypeDecl>(Template->getDeclContext()))
1704 // Look one step prior in a dependent template specialization type.
1740 // to the innermost while checking template-parameter-lists.
1744 // A member or a member template may be nested within many
1747 // template<> for each enclosing class template that is
1768 // We don't have a template header, but we should.
1777 << FixItHint::CreateInsertion(ExpectedTemplateLoc, "template<> ");
1786 // Whether we expect a 'template<>' header.
1789 // Whether we expect a template header with parameters.
1792 // For a dependent type, the set of template parameters that we
1797 // A member or a member template may be nested within many enclosing
1799 // member declaration shall be preceded by a template<> for each
1800 // enclosing class template that is explicitly specialized.
1815 // Members of an explicitly specialized class template are defined
1817 // the template<> syntax.
1832 if (TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
1833 ExpectedTemplateParams = Template->getTemplateParameters();
1837 // FIXME: We actually could/should check the template arguments here
1838 // against the corresponding template parameter list.
1844 // template or a member template that ap- pears in namespace scope, the
1845 // member template and some of its enclosing class templates may remain
1847 // specialize a class member template if its en- closing class templates
1859 // If we're on the last of the types, and we need a 'template<>' header
1866 // The header has template parameters when it shouldn't. Complain.
1877 // Consume this template header.
1891 // In friend declarations we can have template-ids which don't
1892 // depend on the corresponding template parameter lists. But
1894 // template-id.
1904 // Check the template parameter list, if we can.
1928 // If there were at least as many template-ids as there were template
1929 // parameter lists, then there are no template parameter lists remaining for
1933 // We don't have a template header for the declaration itself, but we
1939 // Fabricate an empty template parameter list for the invented header.
1948 // If there were too many template parameter lists, complain about that now.
1965 // If there was a specialization somewhere, such that 'template<>' is
1966 // not required, and there were any 'template<>' headers, note where the
1973 // We have a template parameter list with no corresponding scope, which
1974 // means that the resulting template declaration can't be instantiated
1982 // template or a member template that ap- pears in namespace scope, the
1983 // member template and some of its enclosing class templates may remain
1985 // specialize a class member template if its en- closing class templates
1992 // Return the last template parameter list, which corresponds to the
1998 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
1999 Diag(Template->getLocation(), diag::note_template_declared_here)
2000 << (isa<FunctionTemplateDecl>(Template)
2002 : isa<ClassTemplateDecl>(Template)
2004 : isa<VarTemplateDecl>(Template)
2006 : isa<TypeAliasTemplateDecl>(Template) ? 3 : 4)
2007 << Template->getDeclName();
2053 // The type argument gets reused as the first template argument in the
2054 // synthetic template argument list.
2066 // The first template argument will be reused as the template decl that
2067 // our synthetic template arguments will be applied to.
2080 // When building a template-id where the template-name is dependent,
2081 // assume the template is a type template. Either our assumption is
2089 TemplateDecl *Template = Name.getAsTemplateDecl();
2090 if (!Template || isa<FunctionTemplateDecl>(Template) ||
2091 isa<VarTemplateDecl>(Template)) {
2092 // We might have a substituted template template parameter pack. If so,
2093 // build a template specialization type for it.
2103 // Check that the template argument list is well-formed for this
2104 // template.
2106 if (CheckTemplateArgumentList(Template, TemplateLoc, TemplateArgs,
2114 dyn_cast<TypeAliasTemplateDecl>(Template)) {
2115 // Find the canonical type for this type alias template specialization.
2123 // Only substitute for the innermost template argument list.
2131 InstantiatingTemplate Inst(*this, TemplateLoc, Template);
2143 // This class template specialization is a dependent
2144 // type. Therefore, its canonical type is another class template
2149 // template<typename T, typename U = T> struct A;
2167 if (isa<ClassTemplateDecl>(Template)) {
2177 // and check whether it's the same template.
2199 = dyn_cast<ClassTemplateDecl>(Template)) {
2200 // Find the class template specialization declaration that
2206 // This is the first time we have referenced this class template
2228 } else if (auto *BTD = dyn_cast<BuiltinTemplateDecl>(Template)) {
2233 // Build the fully-sugared type for this class template
2234 // specialization, which refers back to the class template
2249 TemplateName Template = TemplateD.get();
2251 // Translate the parser's template argument list in our AST format.
2255 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
2276 QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs);
2316 TemplateName Template = TemplateD.get();
2318 // Translate the parser's template argument list in our AST format.
2327 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
2349 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
2351 // If the identifier resolves to a typedef-name or the simple-template-id
2352 // resolves to an alias template specialization, the
2358 QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs);
2378 // Provide source-location information for the template specialization.
2437 case TemplateArgument::Template:
2443 llvm_unreachable("unexpected kind of template argument");
2472 /// Convert the parser's template argument list representation into our form.
2487 // D must be variable template id.
2489 "Variable template specialization is declared with a template it.");
2498 TemplateName Name = TemplateId->Template.get();
2500 // The template-id must name a variable template.
2516 // Check for unexpanded parameter packs in any of the template arguments.
2522 // Check that the template argument list is well-formed for this
2523 // template.
2529 // Find the variable template (partial) specialization declaration that
2552 // to the implicit argument list of the primary template.
2554 << /*variable template*/ 1
2558 // of the primary template.
2567 // FIXME: Template parameter list matters too
2574 // Check whether we can declare a variable template specialization in
2582 // Since the only prior variable template specialization with these
2585 // the list of outer template parameters to reflect our new declaration.
2590 // Create a new class template partial specialization declaration node.
2604 // template specialization, make a note of that.
2608 // Check that all of the template parameters of the variable template
2609 // partial specialization are deducible from the template
2610 // arguments. If not, this variable template partial specialization
2620 << /*variable template*/ 1 << (NumNonDeducible > 1)
2635 // Create a new class template specialization declaration node for
2647 // If a template, a member template or the member of a class template is
2698 // Link instantiations of static data members back to the template from
2709 /// \brief A partial specialization whose template arguments have matched
2710 /// a given template-id.
2718 Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
2721 assert(Template && "A variable template id without template?");
2723 // Check that the template argument list is well-formed for this template.
2726 Template, TemplateNameLoc,
2731 // Find the variable template specialization declaration that
2734 if (VarTemplateSpecializationDecl *Spec = Template->findSpecialization(
2736 // If we already have a variable template specialization, return it.
2739 // This is the first time we have referenced this variable template
2743 VarDecl *InstantiationPattern = Template->getTemplatedDecl();
2756 // If any of the template arguments is dependent, then this is probably
2768 Template->getPartialSpecializations(PartialSpecs);
2800 // specializations, then the use of the variable template is
2825 // Instantiate using the best variable template partial specialization.
2830 // from the primary template.
2831 // InstantiationPattern = Template->getTemplatedDecl();
2840 Template, InstantiationPattern, *InstantiationArgs, TemplateArgs,
2865 assert(Decl && "No variable template specialization?");
2872 VarTemplateDecl *Template, SourceLocation TemplateLoc,
2875 DeclResult Decl = CheckVarTemplateId(Template, TemplateLoc, NameInfo.getLoc(),
2896 // template arguments that we have against the template name, if the template
2897 // name refers to a single template. That's not a terribly common case,
2902 // i.e., template<class T> void f(double);
2903 // vs template<class T, class U> void f(U);
2909 // In C++1y, check variable template ids.
2933 // We actually only call this from template instantiation.
2972 /// \brief Form a dependent template name.
2974 /// This action forms a dependent template name given the template
2976 /// example, given "MetaFun::template apply", the scope specifier \p
2978 /// of the "template" keyword, and "apply" is the \p Name.
3000 // If a name prefixed by the keyword template is not the name of
3001 // a template, the program is ill-formed. [Note: the keyword
3002 // template may not be applied to non-template members of class
3004 // typename prefix, the template prefix is allowed in cases
3007 // or . is not dependent on a template-parameter, or the use
3008 // does not appear in the scope of a template. -end note]
3011 // the "template" keyword prior to a template-name that was not a
3013 // "template" keyword is now permitted). We follow the C++0x
3023 // This is a dependent template. Handle it below.
3072 // Check template type parameter.
3076 // A template-argument for a template-parameter which is a
3081 case TemplateArgument::Template: {
3082 // We have a template type parameter but the template argument
3083 // is a template without any arguments.
3094 // We have a template type parameter but the template argument is an
3151 // We have a template type parameter but the template argument
3164 // Add the converted template type argument.
3168 // If an explicitly-specified template argument type is a lifetime type
3182 /// \brief Substitute template arguments into the default template argument for
3183 /// the given template type parameter.
3188 /// \param Template the template that we are synthesizing template arguments
3191 /// \param TemplateLoc the location of the template name that started the
3192 /// template-id we are checking.
3195 /// terminates the template-id.
3197 /// \param Param the template template parameter whose default we are
3200 /// \param Converted the list of template arguments provided for template
3201 /// parameters that precede \p Param in the template parameter list.
3202 /// \returns the substituted template argument, or NULL if an error occurred.
3205 TemplateDecl *Template,
3213 // on the previously-computed template arguments.
3216 Template, Converted,
3224 // Only substitute for the innermost template argument list.
3230 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
3239 /// \brief Substitute template arguments into the default template argument for
3240 /// the given non-type template parameter.
3245 /// \param Template the template that we are synthesizing template arguments
3248 /// \param TemplateLoc the location of the template name that started the
3249 /// template-id we are checking.
3252 /// terminates the template-id.
3254 /// \param Param the non-type template parameter whose default we are
3257 /// \param Converted the list of template arguments provided for template
3258 /// parameters that precede \p Param in the template parameter list.
3260 /// \returns the substituted template argument, or NULL if an error occurred.
3263 TemplateDecl *Template,
3269 Template, Converted,
3277 // Only substitute for the innermost template argument list.
3283 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
3289 /// \brief Substitute template arguments into the default template argument for
3290 /// the given template template parameter.
3295 /// \param Template the template that we are synthesizing template arguments
3298 /// \param TemplateLoc the location of the template name that started the
3299 /// template-id we are checking.
3302 /// terminates the template-id.
3304 /// \param Param the template template parameter whose default we are
3307 /// \param Converted the list of template arguments provided for template
3308 /// parameters that precede \p Param in the template parameter list.
3311 /// source-location information) that precedes the template name.
3313 /// \returns the substituted template argument, or NULL if an error occurred.
3316 TemplateDecl *Template,
3322 Sema::InstantiatingTemplate Inst(SemaRef, TemplateLoc, Template, Converted,
3330 // Only substitute for the innermost template argument list.
3336 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
3353 /// \brief If the given template parameter has a default template
3354 /// argument, substitute into that default template argument and
3355 /// return the corresponding template argument.
3357 Sema::SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
3371 TypeSourceInfo *DI = SubstDefaultTemplateArgument(*this, Template,
3388 ExprResult Arg = SubstDefaultTemplateArgument(*this, Template,
3407 TemplateName TName = SubstDefaultTemplateArgument(*this, Template,
3421 /// \brief Check that the given template argument corresponds to the given
3422 /// template parameter.
3424 /// \param Param The template parameter against which the argument will be
3427 /// \param Arg The template argument, which may be updated due to conversions.
3429 /// \param Template The template in which the template argument resides.
3431 /// \param TemplateLoc The location of the template name for the template
3435 /// the template argument list.
3443 /// \param CTAK Describes how we arrived at this particular template argument:
3449 NamedDecl *Template,
3455 // Check template type parameters.
3459 // Check non-type template parameters.
3461 // Do substitution on the type of the non-type template parameter
3462 // with the template arguments we've seen thus far. But if the
3463 // template has a dependent context then we cannot substitute yet.
3469 !isa<TemplateTemplateParmDecl>(Template) &&
3470 !Template->getDeclContext()->isDependentContext()) {
3471 // Do substitution on the type of the non-type template parameter.
3472 InstantiatingTemplate Inst(*this, TemplateLoc, Template,
3484 // If that worked, check the non-type template parameter type
3495 llvm_unreachable("Should never see a NULL template argument here");
3506 // old expression in the template argument.
3519 // We've already checked this template argument, so just copy
3524 case TemplateArgument::Template:
3526 // We were given a template template argument. It may not be ill-formed;
3531 // We have a template argument such as \c T::template X, which we
3532 // parsed as a template template argument. However, since we now
3533 // know that we need a non-type template argument, convert this
3534 // template name into an expression.
3541 // FIXME: the template-template arg was a DependentTemplateName,
3542 // so it was provided with a template keyword. However, its source
3543 // location is not stored in the template argument structure.
3549 // If we parsed the template
3566 // We have a template argument that actually does refer to a class
3567 // template, alias template, or template template parameter, and
3568 // therefore cannot be a non-type template argument.
3576 // We have a non-type template parameter but the template
3580 // In a template-argument, an ambiguity between a type-id and
3582 // form of the corresponding template-parameter.
3597 llvm_unreachable("Caller must expand template argument packs");
3604 // Check template template parameters.
3607 // Substitute into the template parameter list of the template
3608 // template parameter, since previously-supplied template arguments
3609 // may appear within the template template parameter.
3611 // Set up a template instantiation context.
3613 InstantiatingTemplate Inst(*this, TemplateLoc, Template,
3630 llvm_unreachable("Should never see a NULL template argument here");
3632 case TemplateArgument::Template:
3642 // We have a template template parameter but the template
3643 // argument does not refer to a template.
3649 llvm_unreachable("Declaration argument with template template parameter");
3651 llvm_unreachable("Integral argument with template template parameter");
3653 llvm_unreachable("Null pointer argument with template template parameter");
3656 llvm_unreachable("Caller must expand template argument packs");
3663 static bool diagnoseArityMismatch(Sema &S, TemplateDecl *Template,
3666 TemplateParameterList *Params = Template->getTemplateParameters();
3676 << (isa<ClassTemplateDecl>(Template)? 0 :
3677 isa<FunctionTemplateDecl>(Template)? 1 :
3678 isa<TemplateTemplateParmDecl>(Template)? 2 : 3)
3679 << Template << Range;
3680 S.Diag(Template->getLocation(), diag::note_template_decl_here)
3685 /// \brief Check whether the template parameter is a pack expansion, and if so,
3689 /// template<typename ...Ts> struct A {
3690 /// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3712 /// Diagnose a missing template argument.
3713 template<typename TemplateParmDecl>
3718 // Dig out the most recent declaration of the template parameter; there may be
3719 // declarations of the template that are more recent than TD.
3741 /// \brief Check that the given template argument list is well-formed
3742 /// for specializing the given template.
3743 bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
3748 // Make a copy of the template arguments for processing. Only make the
3750 // template.
3753 TemplateParameterList *Params = Template->getTemplateParameters();
3758 // [...] The type and form of each template-argument specified in
3759 // a template-id shall match the type and form specified for the
3760 // corresponding parameter declared by the template in its
3761 // template-parameter-list.
3762 bool isTemplateTemplateParameter = isa<TemplateTemplateParmDecl>(Template);
3786 << (isa<ClassTemplateDecl>(Template)? 0 :
3787 isa<FunctionTemplateDecl>(Template)? 1 :
3788 isa<TemplateTemplateParmDecl>(Template)? 2 : 3)
3789 << Template;
3790 Diag(Template->getLocation(), diag::note_template_decl_here)
3797 // Check the template argument we were given.
3798 if (CheckTemplateArgument(*Param, NewArgs[ArgIdx], Template,
3806 if (PackExpansionIntoNonPack && isa<TypeAliasTemplateDecl>(Template)) {
3808 // alias template, and it's not part of a parameter pack. This
3821 // The template parameter was a template parameter pack, so take the
3823 // stay on the same template parameter so that we can deduce more
3827 // Move to the next template parameter.
3854 // If we're checking a partial template argument list, we're done.
3863 // If we have a template parameter pack with no more corresponding
3870 // only occurs for an ill-formed template parameter list, unless we've
3871 // got a partial argument list for a function template, so just bail out.
3886 // Retrieve the default template argument from the template
3887 // parameter. For each kind of template parameter, we substitute the
3888 // template arguments provided thus far and any "outer" template arguments
3889 // (when the template parameter was part of a nested template) into
3893 return diagnoseMissingArgument(*this, TemplateLoc, Template, TTP,
3897 Template,
3910 return diagnoseMissingArgument(*this, TemplateLoc, Template, NTTP,
3913 ExprResult E = SubstDefaultTemplateArgument(*this, Template,
3928 return diagnoseMissingArgument(*this, TemplateLoc, Template, TempParm,
3932 TemplateName Name = SubstDefaultTemplateArgument(*this, Template,
3946 // the default template argument.
3947 InstantiatingTemplate Inst(*this, RAngleLoc, Template, *Param, Converted,
3952 // Check the default template argument.
3953 if (CheckTemplateArgument(*Param, Arg, Template
3957 // Core issue 150 (assumed resolution): if this is a template template
3958 // parameter, keep track of the default template arguments from the
3959 // template definition.
3963 // Move to the next template parameter and argument.
3981 return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs);
4229 /// \brief Check a template argument against its corresponding
4230 /// template type parameter.
4249 // template-argument for a template type-parameter.
4277 /// \brief Determine whether the given template argument is a null pointer
4362 // as non-type template arguments, we should return the ExprResult here to
4367 /// \brief Checks whether the given template argument is compatible with its
4368 /// template parameter.
4383 // For a non-type template-parameter of type reference to
4386 // identical) type of the template- argument. The
4387 // template-parameter is bound directly to the
4388 // template-argument, which shall be an lvalue.
4404 // At this point, the template argument refers to an object or
4424 /// \brief Checks whether the given template argument is the address
4480 // A template-argument for a non-type, non-template
4481 // template-parameter shall be one of: [...]
4485 // template-ids but excluding non-static class members,
4488 // corresponding template-parameter is a reference; or
4526 // If our parameter has pointer type, check for a null template value.
4529 // dllimport'd entities aren't constant but are available inside of template
4594 // A non-type template argument must refer to an object or function.
4603 // Address / reference template args must have external linkage in C++98.
4620 // If the template parameter has pointer type, the function decays.
4652 // A template argument must have static storage duration.
4660 // If the template parameter has pointer type, we must have taken
4687 // If the template parameter has pointer type but the address of
4711 // Create the template argument.
4718 /// \brief Checks whether the given template argument is a pointer to
4763 // A template-argument for a non-type, non-template
4764 // template-parameter shall be one of: [...]
4848 /// \brief Check a template argument against its corresponding
4849 /// non-type template parameter.
4853 /// returns the converted template argument. \p ParamType is the
4854 /// type of the non-type template parameter after it has been instantiated.
4871 "non-type template parameter type cannot be qualified");
4876 // If, in the declaration of a function template with a non-type
4877 // template-parameter, the non-type template-parameter is used
4879 // corresponding template-argument is deduced, the
4880 // template-argument type shall match the type of the
4881 // template-parameter exactly, except that a template-argument
4899 // A template-argument for a non-type template parameter shall be
4900 // a converted constant expression of the type of the template-parameter.
4937 // For a non-type template-parameter of pointer or reference type,
4987 llvm_unreachable("invalid kind for template argument");
4995 // as a non-type template-argument. If a non-type
4996 // template-argument cannot be converted to the type of the
4997 // corresponding template-parameter then the program is
5001 // -- for a non-type template-parameter of integral or
5006 // -- for a non-type template-parameter of integral or
5012 // FIXME: If there's no viable conversion to the template parameter type,
5020 // A template-argument for a non-type, non-template template-parameter
5023 // -- for a non-type template-parameter of integral or enumeration
5025 // template-parameter; or
5054 // A template-argument for a non-type, non-template
5055 // template-parameter shall be one of:
5059 // -- the name of a non-type template-parameter; or
5111 // arguments. We use the bitwidth and signedness of the template
5134 // Coerce the template argument's value to the value it will have
5135 // based on the template parameter's type.
5150 // Complain if we overflowed the template parameter's type.
5179 if (// -- For a non-type template-parameter of type pointer to
5181 // applied. If the template-argument represents a set of
5186 // -- For a non-type template-parameter of type reference to
5187 // function, no conversions apply. If the template-argument
5192 // -- For a non-type template-parameter of type pointer to
5194 // template-argument represents a set of overloaded member
5229 // -- for a non-type template-parameter of type pointer to
5244 // -- For a non-type template-parameter of type reference to
5247 // identical) type of the template-argument. The
5248 // template-parameter is bound directly to the
5249 // template-argument, which must be an lvalue.
5299 // -- For a non-type template-parameter of type pointer to data
5309 /// \brief Check a template argument against its corresponding
5310 /// template template parameter.
5312 /// This routine implements the semantics of C++ [temp.arg.template].
5318 TemplateDecl *Template = Name.getAsTemplateDecl();
5319 if (!Template) {
5320 // Any dependent template name is fine.
5321 assert(Name.isDependent() && "Non-dependent template isn't a declaration?");
5325 // C++0x [temp.arg.template]p1:
5326 // A template-argument for a template template-parameter shall be
5327 // the name of a class template or an alias template, expressed as an
5328 // id-expression. When the template-argument names a class template, only
5330 // template template argument with the corresponding parameter;
5332 // parameter lists match that of the template template parameter.
5334 // Note that we also allow template template parameters here, which
5335 // will happen when we are dealing with, e.g., class template
5337 if (!isa<ClassTemplateDecl>(Template) &&
5338 !isa<TemplateTemplateParmDecl>(Template) &&
5339 !isa<TypeAliasTemplateDecl>(Template)) {
5340 assert(isa<FunctionTemplateDecl>(Template) &&
5343 Diag(Template->getLocation(), diag::note_template_arg_refers_here_func)
5344 << Template;
5351 return !TemplateParameterListsAreEqual(Template->getTemplateParameters(),
5358 /// \brief Given a non-type template argument that refers to a
5359 /// declaration and the type of its corresponding non-type template
5368 // A non-type template-parameter of type "array of T" or
5376 // For a NULL non-type template argument, return nullptr casted to the
5387 "Only declaration template arguments permitted here");
5395 // Determine whether the non-type template template parameter is of
5444 // When the non-type template parameter is a pointer, take the
5465 // If the non-type template parameter has reference type, qualify the
5481 /// integral template argument with the given source-location
5484 /// This routine takes care of the mapping from an integral template
5491 "Operation is only valid for integral template arguments");
5528 // non-type template parameters.
5538 /// \brief Match two template parameters within template parameter lists.
5543 // Check the actual kind (type, non-type, template).
5561 // However, if we are matching a template template argument to a
5562 // template template parameter, the template template parameter can have
5563 // a parameter pack where the template template argument does not.
5587 // For non-type template parameters, check the type of the parameter.
5592 // If we are matching a template template argument to a template
5593 // template parameter and one of the non-type template parameter types
5594 // is dependent, then we must wait until template instantiation time
5623 template template parameters, check the template parameter types.
5624 // The template parameter lists of template template
5641 /// \brief Diagnose a known arity mismatch when comparing template argument
5663 /// \brief Determine whether the given template parameter lists are
5666 /// \param New The new template parameter list, typically written in the
5667 /// source code as part of a new template declaration.
5669 /// \param Old The old template parameter list, typically found via
5670 /// name lookup of the template declared with this template parameter
5674 /// the template parameter lists are not equivalent.
5676 /// \param Kind describes how we are to match the template parameter lists.
5679 /// are actually checking the template parameter list of a template
5680 /// argument (New) against the template parameter list of its
5681 /// corresponding template template parameter (Old). We produce
5684 /// \returns True if the template parameter lists are equal, false
5700 // C++0x [temp.arg.template]p3:
5701 // A template-argument matches a template template-parameter (call it P)
5702 // when each of the template parameters in the template-parameter-list of
5703 // the template-argument's corresponding class template or alias template
5704 // (call it A) matches the corresponding template parameter in the
5705 // template-parameter-list of P. [...]
5729 // C++0x [temp.arg.template]p3:
5730 // [...] When P's template- parameter-list contains a template parameter
5731 // pack (14.5.3), the template parameter pack will match zero or more
5732 // template parameters or template parameter packs in the
5733 // template-parameter-list of A with the same type and form as the
5734 // template parameter pack in P (ignoring whether those template
5735 // parameters are template parameter packs).
5755 /// \brief Check whether a template can be declared within this scope.
5757 /// If the template declaration is valid in this scope, returns
5770 // A template [...] shall not have C linkage.
5780 // A template-declaration can appear only as a namespace scope or
5802 /// \brief Determine what kind of template specialization the given declaration
5821 /// This routine determines whether a template specialization can be declared
5828 /// may be a kind of template (class template, function template, etc.) or
5829 /// a member of a class template (member function, static data member,
5838 /// a class template.
5873 // of which the template is a member, or, for member templates, in
5875 // template is a member. An explicit specialization of a member
5877 // template shall be declared in the namespace of which the class
5878 // template is a member. Such a declaration may also be a
5915 // A class template partial specialization may be declared or redeclared
5953 // the template is a member, or, for member templates, in the namespace
5954 // of which the enclosing class or enclosing class template is a member.
5956 // static data member of a class template shall be declared in the
5957 // namespace of which the class template is a member.
5961 // the specialized template.
5964 // template.
6012 /// that checks non-type template partial specialization arguments.
6052 // Within the argument list of a class template partial
6055 // shall not involve a template parameter of the partial
6075 // -- The type of a template parameter corresponding to a
6081 // template<template<typename> class X> struct A {
6082 // template<typename T, X<T> N> struct B;
6083 // template<typename T> struct B<T, 0>;
6085 // template<typename> using X = int;
6102 /// \brief Check the non-type template arguments of a class template
6105 /// \param TemplateNameLoc the location of the template name.
6106 /// \param TemplateParams the template parameters of the primary class
6107 /// template.
6108 /// \param NumExplicit the number of explicitly-specified template arguments.
6109 /// \param TemplateArgs the template arguments of the class template
6148 // store the location of the outermost template keyword in the declaration.
6155 // Find the class template we're specializing
6156 TemplateName Name = TemplateId.Template.get();
6170 // Check the validity of the template headers that introduce this
6171 // template.
6193 // The template parameter list of a specialization shall not
6194 // contain default template argument values.
6231 assert(TUK == TUK_Friend && "should have a 'template<>' for this decl");
6235 // original template.
6237 assert(Kind != TTK_Enum && "Invalid enum tag in class template spec!");
6250 // Translate the parser's template argument list in our AST format.
6254 // Check for unexpanded parameter packs in any of the template arguments.
6260 // Check that the template argument list is well-formed for this
6261 // template.
6267 // Find the class template (partial) specialization declaration that
6291 // FIXME: Template parameter list matters, too
6298 // Check whether we can declare a class template specialization in
6309 // Build the canonical type that describes the converted template
6310 // arguments of the class template partial specialization.
6321 // to the implicit argument list of the primary template.
6323 << /*class template*/0 << (TUK == TUK_Definition)
6336 // Create a new class template partial specialization declaration node.
6361 // template specialization, make a note of that.
6365 // Check that all of the template parameters of the class template
6366 // partial specialization are deducible from the template
6367 // arguments. If not, this class template partial specialization
6377 << /*class template*/0 << (NumNonDeducible > 1)
6394 // Create a new class template specialization declaration node for
6427 // If a template, a member template or the member of a class template is
6493 // Build the fully-sugared type for this class template
6499 // template arguments in the specialization.
6509 // A template explicit specialization is in the scope of the
6510 // namespace in which the template was defined.
6573 /// \brief Diagnose cases where we have an explicit template specialization
6574 /// before/after an explicit template instantiation, producing diagnostics
6637 // If a template, a member template or the member of a class template
6671 // For a given set of template parameters, if an explicit instantiation
6672 // of a template appears after a declaration of an explicit
6673 // specialization for that template, the explicit instantiation has no
6705 // For a given set of template parameters, if an explicit
6706 // instantiation of a template appears after a declaration of
6707 // an explicit specialization for that template, the explicit
6727 // For a given set of template parameters, if an explicit instantiation
6728 // of a template appears after a declaration of an explicit
6729 // specialization for that template, the explicit instantiation has no
6743 // For a given template and a given set of template-arguments,
6763 /// template specialization.
6765 /// The only possible way to get a dependent function template specialization
6769 /// template \<class T> void foo(T);
6770 /// template \<class T> class A {
6781 // Remove anything from Previous that isn't a function template in
6802 /// \brief Perform semantic analysis for the given function template
6806 /// explicit function template specialization. On successful completion,
6807 /// the function declaration \p FD will become a function template
6811 /// function template specialization.
6813 /// \param ExplicitTemplateArgs the explicitly-provided template arguments,
6823 // The set of function template specializations that could match this
6824 // explicit function template specialization.
6843 // When matching a constexpr member function template specialization
6844 // against the primary template, we don't yet know whether the
6846 // it will be a static member function until we know which template it
6847 // specializes), so adjust it now assuming it specializes this template.
6866 // A trailing template-argument can be left unspecified in the
6867 // template-id naming an explicit function template specialization
6869 // Perform template argument deduction to determine whether we may be
6870 // specializing this template.
6877 // Template argument deduction failed; record why it failed, so
6893 // Find the most specialized function template.
6910 assert(SpecInfo && "Function template specialization info missing?");
6912 // Note: do not overwrite location info if previous template
6918 // function can differ from the template declaration with respect to
6939 // If a template, a member template or the member of a class template is
6961 // Turn the given function declaration into a function template
6962 // specialization, with the template arguments from the previous
6964 // Take copies of (semantic and syntactic) template argument lists.
6972 // The "previous declaration" for this function template specialization is
6973 // the prior function template specialization.
6979 /// \brief Perform semantic analysis for the given non-template member
6995 assert(!isa<TemplateDecl>(Member) && "Only for non-template members");
7082 // If a template, a member template or the member of a class template is
7184 // template. If the name declared in the explicit instantiation is an
7186 // namespace where its template is declared or, if that namespace is inline
7221 /// \brief Determine whether the given scope specifier has a template-id in it.
7228 // or a static data member of a class template specialization, the name of
7229 // the class template specialization in the qualified-id for the member
7230 // name shall be a simple-template-id.
7242 // Explicit instantiation of a class template specialization
7256 // Find the class template we're specializing
7260 // original template.
7263 "Invalid enum tag in class template explicit instantiation!");
7295 // Check for dllexport class template instantiation declarations.
7312 // Translate the parser's template argument list in our AST format.
7316 // Check that the template argument list is well-formed for this
7317 // template.
7323 // Find the class template specialization declaration that
7334 // namespace of its template. [...]
7356 // Since the only prior class template specialization with these
7359 // for the template name to reflect our new declaration.
7368 // Create a new class template specialization declaration node for
7391 // on the "canonical" representation used to store the template
7415 // Set the template specialization kind.
7421 // A definition of a class template or class member template
7423 // the class template or class member template.
7437 // Instantiate the members of this class template specialization.
7453 // attribute to a template with a previous instantiation declaration.
7470 // Set the template specialization kind. Make sure it is set before
7476 // Set the template specialization kind.
7483 // Explicit instantiation of a member class of a class template.
7526 // simple-template-id.
7543 // namespace of its template. [...]
7571 // A definition of a member class of a class template shall be in scope
7654 // [...] An explicit instantiation of a function template shall not use the
7683 // A [...] static data member of a class template can be explicitly
7685 // template.
7687 // A [...] variable [...] template specialization can be explicitly
7688 // instantiated from its template.
7716 // Explicitly instantiate a variable template.
7722 // This includes auto-typed variable template instantiations.
7732 // in the declaration shall be a template-id.
7741 // Translate the parser's template argument list into our AST format.
7757 // or a static data member of a class template specialization, the name of
7758 // the class template specialization in the qualified-id for the member
7759 // name shall be a simple-template-id.
7763 // This does not apply to variable template specializations, where the
7764 // template-id is in the unqualified-id instead.
7782 // Instantiate static data member or variable template.
7808 // If the declarator is a template-id, translate the parser's template
7818 // A [...] function [...] can be explicitly instantiated from its template.
7819 // A member function [...] of a class template can be explicitly
7821 // template.
7862 // Find the most specialized function template specialization.
7942 // or a static data member of a class template specialization, the name of
7943 // the class template specialization in the qualified-id for the member
7944 // name shall be a simple-template-id.
8050 // Translate the parser's template argument list in our AST format.
8054 TemplateName Template = TemplateIn.get();
8055 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
8056 // Construct a dependent template specialization type.
8057 assert(DTN && "dependent template has non-dependent name?");
8079 QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
8083 // Provide source-location information for the template specialization type.
8112 // ... within an explicitly-written template specialization...
8123 // ... which names a complete class template declaration...
8135 // Assume the first template argument is the condition.
8177 // If we're looking up 'type' within a template named 'enable_if', produce
8296 /// a class template (or class template partial specialization) that was parsed
8297 /// and constructed before we entered the scope of the class template (or
8303 /// template<typename T>
8309 /// template<typename T>
8351 /// \brief Rebuild the template parameters now that we know we're in a current
8362 // Rebuild the template parameter list of a template template parameter.
8372 // Rebuild the type of a non-type template parameter.
8391 /// template parameters to template arguments.