Lines Matching refs:Template
27 #include "clang/Sema/Template.h"
44 /// of a template and, if so, return that template declaration. Otherwise,
60 // Like normal (non-template) classes, class templates have an
62 // can be used with or without a template-argument-list. When
63 // it is used without a template-argument-list, it is
65 // template-parameters of the class template enclosed in
66 // <>. When it is used with a template-argument-list, it
67 // refers to the specified class template specialization,
103 // refer to specializations of the same class template, and if the name
104 // is used as a template-name, the reference refers to the class
105 // template itself and not a specialization thereof, and is not
115 // found this template through a particular injected class name,
141 assert(getLangOpts().CPlusPlus && "No template names in C!");
179 TemplateName Template;
185 // template name in other ways.
186 Template = Context.getOverloadedTemplateName(R.begin(), R.end());
197 Template = Context.getQualifiedTemplateName(Qualifier,
200 Template = TemplateName(TD);
215 TemplateResult = TemplateTy::make(Template);
226 // template name.
232 // The code is missing a 'template' keyword prior to the dependent template
237 << FixItHint::CreateInsertion(IILoc, "template ");
262 // Template names cannot appear inside an Objective-C class or object type.
291 // beginning of a template argument list (14.2) or a less-than operator.
295 // or function template.
342 if (TemplateDecl *Template = Found.getAsSingle<TemplateDecl>())
343 Diag(Template->getLocation(), diag::note_previous_decl)
362 // template, the name is also looked up in the context of the entire
377 // postfix-expression and does not name a class template, the name
381 // - if the name found is a class template, it must refer to the same
397 // Recover by taking the template that we found in the object
451 /// that the template parameter 'PrevDecl' is being shadowed by a new
455 assert(PrevDecl->isTemplateParameter() && "Not a template parameter");
457 // Microsoft Visual C++ permits template parameters to be shadowed.
462 // A template-parameter shall not be redeclared within its
470 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
472 /// to the template declaration. Otherwise, do nothing to D and return null.
483 assert(Kind == Template &&
484 "Only template template arguments can be pack expansions here");
486 "Template template argument pack expansion without packs");
509 case ParsedTemplateArgument::Template: {
510 TemplateName Template = Arg.getAsTemplate().get();
513 TArg = TemplateArgument(Template, Optional<unsigned int>());
515 TArg = Template;
524 llvm_unreachable("Unhandled parsed template argument");
527 /// \brief Translates template arguments as provided by the parser
528 /// into template arguments used by semantic analysis.
536 /// ActOnTypeParameter - Called when a C++ template type parameter
541 /// parameter (NULL indicates an unnamed template parameter) and
554 "Template type parameter not in template parameter scope!");
580 // Add the template parameter into the current scope.
586 // A default template-argument may be specified for any kind of
587 // template-parameter that is not a template parameter pack.
605 // Check the template argument itself.
617 /// \brief Check that the type of a non-type template parameter is
624 // We don't allow variably-modified types as the type of non-type template
634 // A non-type template-parameter shall have one of the following
650 // C++ [temp.param]p5: The top-level cv-qualifiers on the template-parameter
657 // A non-type template-parameter of type "array of T" or
682 "Non-type template parameter not in template parameter scope!");
715 // Add the template parameter into the current scope.
721 // A default template-argument may be specified for any kind of
722 // template-parameter that is not a template parameter pack.
728 // Check the well-formedness of the default template argument, if provided.
748 /// ActOnTemplateTemplateParameter - Called when a C++ template template
749 /// parameter (e.g. T in template <template \<typename> class T> class array)
762 "Template template parameter not in template parameter scope!");
773 // If the template template parameter has a name, then link the identifier
787 // A default template-argument may be specified for any kind of
788 // template-parameter that is not a template parameter pack.
795 // Check only that we have a template template argument. We don't want to
796 // try to check well-formedness now, because our template template parameter
797 // might have dependent types in its template parameters, which we wouldn't
800 // If none of the template template parameter's template arguments mention
801 // other template parameters, we could actually perform more checking here.
823 template parameters in Params/NumParams.
854 "No template parameters");
858 // Check that we can declare a template here.
863 assert(Kind != TTK_Enum && "can't build template of enumerated type");
865 // There is no such thing as an unnamed class template.
894 // If we're adding a template to a dependent context, we may need to
895 // rebuilding some of the types used within the template parameter list,
922 // We may have found the injected-class-name of a class template,
923 // class template partial specialization, or class template specialization.
924 // In these cases, grab the template that is being defined or specialized.
941 // function is neither a qualified name nor a template-id, scopes outside
979 // Ensure that the template parameter lists are compatible. Skip this check
980 // for a friend in a dependent context: the template parameter list itself
991 // specialization or explicit instantiation of a class template,
993 // template declaration (7.1.5.3).
1004 // Check for redefinition of this class template.
1015 // Maybe we will complain about the shadowed template parameter.
1021 // A class template shall not have the same name as any other
1022 // template, class, function, object, enumeration, enumerator,
1030 // Check the template parameter list of this declaration, possibly
1031 // merging in the template parameter list from the previous class
1032 // template declaration. Skip this check for a friend in a dependent
1033 // context, because the template parameter list might be dependent.
1045 // If the name of the template was qualified, we must be defining the
1046 // template out-of-line.
1082 // Build the type for the class template declaration now.
1085 assert(T->isDependentType() && "Class template type is not dependent?");
1089 // class template, make a note of that.
1151 /// \brief Diagnose the presence of a default template argument on a
1152 /// template parameter, which is ill-formed in certain contexts.
1154 /// \returns true if the default template argument should be dropped.
1167 // A default template-argument shall not be specified in a
1168 // function template declaration or a function template
1170 // If a friend function template declaration specifies a default
1171 // template-argument, that declaration shall be a definition and shall be
1172 // the only declaration of the function template in the translation unit.
1182 // A default template-argument shall not be specified in the
1183 // template-parameter-lists of the definition of a member of a
1184 // class template that appears outside of the member's class.
1191 // A default template-argument shall not be specified in a
1192 // friend template declaration.
1197 // FIXME: C++0x [temp.param]p9 allows default template-arguments
1205 /// \brief Check for unexpanded parameter packs within the template parameters
1206 /// of a template template parameter, recursively.
1209 // A template template parameter which is a parameter pack is also a pack
1236 /// \brief Checks the validity of a template parameter list, possibly
1237 /// considering the template parameter list from a previous
1240 /// If an "old" template parameter list is provided, it must be
1242 /// template parameter list.
1244 /// \param NewParams Template parameter list for a new template
1245 /// declaration. This template parameter list will be updated with any
1247 /// template parameter list.
1249 /// \param OldParams If provided, template parameter list from a
1250 /// previous declaration of the same template. Default template
1251 /// arguments will be merged from the old template parameter list to
1252 /// the new template parameter list.
1255 /// template parameter list.
1264 // The set of default template-arguments available for use with a
1265 // template declaration or definition is obtained by merging the
1302 // Merge default arguments for template type parameters.
1348 // Merge default arguments for non-type template parameters
1368 // expression that points to a previous non-type template
1396 // Merge default arguments for template template parameters
1416 // that points to a previous template template parameter.
1431 // If a template parameter of a primary class template or alias template
1432 // is a template parameter pack, it shall be the last template parameter.
1442 // A template-parameter shall not be given default arguments
1449 // If a template-parameter of a class template has a default
1450 // template-argument, each subsequent template-parameter shall either
1451 // have a default template-argument supplied or be a template parameter
1460 // If we have an old template parameter list that we're merging
1487 /// A class which looks for a use of a certain level of template
1571 /// \brief Match the given template parameter lists to the given scope
1572 /// specifier, returning the template parameter list that applies to the
1576 /// specifier or a template parameter list.
1580 /// \param SS the scope specifier that will be matched to the given template
1584 /// \param ParamLists the template parameter lists, from the outermost to the
1585 /// innermost template parameter lists.
1587 /// \param NumParamLists the number of template parameter lists in ParamLists.
1590 /// matching template parameters to scope specifiers in friend
1596 /// \returns the template parameter list, if any, that corresponds to the
1597 /// name that is preceded by the scope specifier @p SS. This template
1598 /// parameter list may have template parameters (if we're declaring a
1599 /// template) or may have no template parameters (if we're declaring a
1600 /// template specialization), or may be NULL (if what we're declaring isn't
1601 /// itself a template).
1614 // The sequence of nested types to which we will match up the template
1628 // 'template<>' headers, this will be set to the location of that
1660 if (TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
1661 if (TypeDecl *Parent = dyn_cast<TypeDecl>(Template->getDeclContext()))
1669 // Look one step prior in a dependent template specialization type.
1705 // to the innermost while checking template-parameter-lists.
1709 // A member or a member template may be nested within many
1712 // template<> for each enclosing class template that is
1720 // Whether we expect a 'template<>' header.
1723 // Whether we expect a template header with parameters.
1726 // For a dependent type, the set of template parameters that we
1731 // A member or a member template may be nested within many enclosing
1733 // member declaration shall be preceded by a template<> for each
1734 // enclosing class template that is explicitly specialized.
1749 // Members of an explicitly specialized class template are defined
1751 // the template<> syntax.
1766 if (TemplateDecl *Template = TST->getTemplateName().getAsTemplateDecl()) {
1767 ExpectedTemplateParams = Template->getTemplateParameters();
1771 // FIXME: We actually could/should check the template arguments here
1772 // against the corresponding template parameter list.
1778 // template or a member template that ap- pears in namespace scope, the
1779 // member template and some of its enclosing class templates may remain
1781 // specialize a class member template if its en- closing class templates
1797 // If we're on the last of the types, and we need a 'template<>' header
1804 // The header has template parameters when it shouldn't. Complain.
1815 // Consume this template header.
1821 // We don't have a template header, but we should.
1830 << FixItHint::CreateInsertion(ExpectedTemplateLoc, "template<> ");
1837 // In friend declarations we can have template-ids which don't
1838 // depend on the corresponding template parameter lists. But
1840 // template-id.
1850 // Check the template parameter list, if we can.
1874 // If there were at least as many template-ids as there were template
1875 // parameter lists, then there are no template parameter lists remaining for
1880 // If there were too many template parameter lists, complain about that now.
1897 // If there was a specialization somewhere, such that 'template<>' is
1898 // not required, and there were any 'template<>' headers, note where the
1905 // We have a template parameter list with no corresponding scope, which
1906 // means that the resulting template declaration can't be instantiated
1914 // template or a member template that ap- pears in namespace scope, the
1915 // member template and some of its enclosing class templates may remain
1917 // specialize a class member template if its en- closing class templates
1928 // Return the last template parameter list, which corresponds to the
1934 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
1935 Diag(Template->getLocation(), diag::note_template_declared_here)
1936 << (isa<FunctionTemplateDecl>(Template)? 0
1937 : isa<ClassTemplateDecl>(Template)? 1
1938 : isa<TypeAliasTemplateDecl>(Template)? 2
1940 << Template->getDeclName();
1961 // When building a template-id where the template-name is dependent,
1962 // assume the template is a type template. Either our assumption is
1970 TemplateDecl *Template = Name.getAsTemplateDecl();
1971 if (!Template || isa<FunctionTemplateDecl>(Template)) {
1972 // We might have a substituted template template parameter pack. If so,
1973 // build a template specialization type for it.
1983 // Check that the template argument list is well-formed for this
1984 // template.
1987 if (CheckTemplateArgumentList(Template, TemplateLoc, TemplateArgs,
1996 (AliasTemplate = dyn_cast<TypeAliasTemplateDecl>(Template))) {
1997 // Find the canonical type for this type alias template specialization.
2005 // Only substitute for the innermost template argument list.
2013 InstantiatingTemplate Inst(*this, TemplateLoc, Template);
2025 // This class template specialization is a dependent
2026 // type. Therefore, its canonical type is another class template
2031 // template<typename T, typename U = T> struct A;
2049 if (isa<ClassTemplateDecl>(Template)) {
2059 // and check whether it's the same template.
2081 = dyn_cast<ClassTemplateDecl>(Template)) {
2082 // Find the class template specialization declaration that
2089 // This is the first time we have referenced this class template
2110 // Build the fully-sugared type for this class template
2111 // specialization, which refers back to the class template
2126 TemplateName Template = TemplateD.getAsVal<TemplateName>();
2128 // Translate the parser's template argument list in our AST format.
2132 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
2153 QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs);
2193 TemplateName Template = TemplateD.getAsVal<TemplateName>();
2195 // Translate the parser's template argument list in our AST format.
2204 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
2226 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
2228 // If the identifier resolves to a typedef-name or the simple-template-id
2229 // resolves to an alias template specialization, the
2235 QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs);
2255 // Provide source-location information for the template specialization.
2281 // template arguments that we have against the template name, if the template
2282 // name refers to a single template. That's not a terribly common case,
2287 // i.e., template<class T> void f(double);
2288 // vs template<class T, class U> void f(U);
2308 // We actually only call this from template instantiation.
2346 /// \brief Form a dependent template name.
2348 /// This action forms a dependent template name given the template
2350 /// example, given "MetaFun::template apply", the scope specifier \p
2352 /// of the "template" keyword, and "apply" is the \p Name.
2374 // If a name prefixed by the keyword template is not the name of
2375 // a template, the program is ill-formed. [Note: the keyword
2376 // template may not be applied to non-template members of class
2378 // typename prefix, the template prefix is allowed in cases
2381 // or . is not dependent on a template-parameter, or the use
2382 // does not appear in the scope of a template. -end note]
2385 // the "template" keyword prior to a template-name that was not a
2387 // "template" keyword is now permitted). We follow the C++0x
2397 // This is a dependent template. Handle it below.
2446 // Check template type parameter.
2450 // A template-argument for a template-parameter which is a
2453 case TemplateArgument::Template: {
2454 // We have a template type parameter but the template argument
2455 // is a template without any arguments.
2466 // We have a template type parameter but the template argument is an
2493 // FIXME: Add a FixIt and fix up the template argument for recovery.
2503 // We have a template type parameter but the template argument
2516 // Add the converted template type argument.
2520 // If an explicitly-specified template argument type is a lifetime type
2534 /// \brief Substitute template arguments into the default template argument for
2535 /// the given template type parameter.
2540 /// \param Template the template that we are synthesizing template arguments
2543 /// \param TemplateLoc the location of the template name that started the
2544 /// template-id we are checking.
2547 /// terminates the template-id.
2549 /// \param Param the template template parameter whose default we are
2552 /// \param Converted the list of template arguments provided for template
2553 /// parameters that precede \p Param in the template parameter list.
2554 /// \returns the substituted template argument, or NULL if an error occurred.
2557 TemplateDecl *Template,
2565 // on the previously-computed template arguments.
2571 = SemaRef.getTemplateInstantiationArgs(Template, &TemplateArgs);
2574 Template, Converted,
2579 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
2588 /// \brief Substitute template arguments into the default template argument for
2589 /// the given non-type template parameter.
2594 /// \param Template the template that we are synthesizing template arguments
2597 /// \param TemplateLoc the location of the template name that started the
2598 /// template-id we are checking.
2601 /// terminates the template-id.
2603 /// \param Param the non-type template parameter whose default we are
2606 /// \param Converted the list of template arguments provided for template
2607 /// parameters that precede \p Param in the template parameter list.
2609 /// \returns the substituted template argument, or NULL if an error occurred.
2612 TemplateDecl *Template,
2621 = SemaRef.getTemplateInstantiationArgs(Template, &TemplateArgs);
2624 Template, Converted,
2629 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
2634 /// \brief Substitute template arguments into the default template argument for
2635 /// the given template template parameter.
2640 /// \param Template the template that we are synthesizing template arguments
2643 /// \param TemplateLoc the location of the template name that started the
2644 /// template-id we are checking.
2647 /// terminates the template-id.
2649 /// \param Param the template template parameter whose default we are
2652 /// \param Converted the list of template arguments provided for template
2653 /// parameters that precede \p Param in the template parameter list.
2656 /// source-location information) that precedes the template name.
2658 /// \returns the substituted template argument, or NULL if an error occurred.
2661 TemplateDecl *Template,
2671 = SemaRef.getTemplateInstantiationArgs(Template, &TemplateArgs);
2674 Template, Converted,
2679 Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
2695 /// \brief If the given template parameter has a default template
2696 /// argument, substitute into that default template argument and
2697 /// return the corresponding template argument.
2699 Sema::SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
2708 TypeSourceInfo *DI = SubstDefaultTemplateArgument(*this, Template,
2724 ExprResult Arg = SubstDefaultTemplateArgument(*this, Template,
2743 TemplateName TName = SubstDefaultTemplateArgument(*this, Template,
2757 /// \brief Check that the given template argument corresponds to the given
2758 /// template parameter.
2760 /// \param Param The template parameter against which the argument will be
2763 template argument.
2765 /// \param Template The template in which the template argument resides.
2767 /// \param TemplateLoc The location of the template name for the template
2771 /// the template argument list.
2779 /// \param CTAK Describes how we arrived at this particular template argument:
2785 NamedDecl *Template,
2791 // Check template type parameters.
2795 // Check non-type template parameters.
2797 // Do substitution on the type of the non-type template parameter
2798 // with the template arguments we've seen thus far. But if the
2799 // template has a dependent context then we cannot substitute yet.
2805 !isa<TemplateTemplateParmDecl>(Template) &&
2806 !Template->getDeclContext()->isDependentContext()) {
2807 // Do substitution on the type of the non-type template parameter.
2808 InstantiatingTemplate Inst(*this, TemplateLoc, Template,
2820 // If that worked, check the non-type template parameter type
2831 llvm_unreachable("Should never see a NULL template argument here");
2848 // We've already checked this template argument, so just copy
2853 case TemplateArgument::Template:
2855 // We were given a template template argument. It may not be ill-formed;
2860 // We have a template argument such as \c T::template X, which we
2861 // parsed as a template template argument. However, since we now
2862 // know that we need a non-type template argument, convert this
2863 // template name into an expression.
2870 // FIXME: the template-template arg was a DependentTemplateName,
2871 // so it was provided with a template keyword. However, its source
2872 // location is not stored in the template argument structure.
2879 // If we parsed the template argument as a pack expansion, create a
2896 // We have a template argument that actually does refer to a class
2897 // template, alias template, or template template parameter, and
2898 // therefore cannot be a non-type template argument.
2906 // We have a non-type template parameter but the template
2910 // In a template-argument, an ambiguity between a type-id and
2912 // form of the corresponding template-parameter.
2927 llvm_unreachable("Caller must expand template argument packs");
2934 // Check template template parameters.
2937 // Substitute into the template parameter list of the template
2938 // template parameter, since previously-supplied template arguments
2939 // may appear within the template template parameter.
2941 // Set up a template instantiation context.
2943 InstantiatingTemplate Inst(*this, TemplateLoc, Template,
2960 llvm_unreachable("Should never see a NULL template argument here");
2962 case TemplateArgument::Template:
2972 // We have a template template parameter but the template
2973 // argument does not refer to a template.
2979 llvm_unreachable("Declaration argument with template template parameter");
2981 llvm_unreachable("Integral argument with template template parameter");
2983 llvm_unreachable("Null pointer argument with template template parameter");
2986 llvm_unreachable("Caller must expand template argument packs");
2993 static bool diagnoseArityMismatch(Sema &S, TemplateDecl *Template,
2996 TemplateParameterList *Params = Template->getTemplateParameters();
3006 << (isa<ClassTemplateDecl>(Template)? 0 :
3007 isa<FunctionTemplateDecl>(Template)? 1 :
3008 isa<TemplateTemplateParmDecl>(Template)? 2 : 3)
3009 << Template << Range;
3010 S.Diag(Template->getLocation(), diag::note_template_decl_here)
3015 /// \brief Check whether the template parameter is a pack expansion, and if so,
3019 /// template<typename ...Ts> struct A {
3020 /// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3042 /// \brief Check that the given template argument list is well-formed
3043 /// for specializing the given template.
3044 bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
3053 TemplateParameterList *Params = Template->getTemplateParameters();
3058 // [...] The type and form of each template-argument specified in
3059 // a template-id shall match the type and form specified for the
3060 // corresponding parameter declared by the template in its
3061 // template-parameter-list.
3062 bool isTemplateTemplateParameter = isa<TemplateTemplateParmDecl>(Template);
3088 << (isa<ClassTemplateDecl>(Template)? 0 :
3089 isa<FunctionTemplateDecl>(Template)? 1 :
3090 isa<TemplateTemplateParmDecl>(Template)? 2 : 3)
3091 << Template;
3092 Diag(Template->getLocation(), diag::note_template_decl_here)
3099 // Check the template argument we were given.
3100 if (CheckTemplateArgument(*Param, TemplateArgs[ArgIdx], Template,
3109 // The template parameter was a template parameter pack, so take the
3111 // stay on the same template parameter so that we can deduce more
3116 // Move to the next template parameter.
3163 // If we're checking a partial template argument list, we're done.
3173 // If we have a template parameter pack with no more corresponding
3180 // only occurs for an ill-formed template parameter list, unless we've
3181 // got a partial argument list for a function template, so just bail out.
3197 // Retrieve the default template argument from the template
3198 // parameter. For each kind of template parameter, we substitute the
3199 // template arguments provided thus far and any "outer" template arguments
3200 // (when the template parameter was part of a nested template) into
3204 return diagnoseArityMismatch(*this, Template, TemplateLoc,
3208 Template,
3221 return diagnoseArityMismatch(*this, Template, TemplateLoc,
3224 ExprResult E = SubstDefaultTemplateArgument(*this, Template,
3239 return diagnoseArityMismatch(*this, Template, TemplateLoc,
3243 TemplateName Name = SubstDefaultTemplateArgument(*this, Template,
3257 // the default template argument.
3258 InstantiatingTemplate Instantiating(*this, RAngleLoc, Template,
3264 // Check the default template argument.
3265 if (CheckTemplateArgument(*Param, Arg, Template, TemplateLoc,
3269 // Core issue 150 (assumed resolution): if this is a template template
3270 // parameter, keep track of the default template arguments from the
3271 // template definition.
3275 // Move to the next template parameter and argument.
3283 return diagnoseArityMismatch(*this, Template, TemplateLoc, TemplateArgs);
3528 /// \brief Check a template argument against its corresponding
3529 /// template type parameter.
3548 // template-argument for a template type-parameter.
3571 /// \brief Determine whether the given template argument is a null pointer
3653 // as non-type template arguments, we should return the ExprResult here to
3658 /// \brief Checks whether the given template argument is the address
3670 // If our parameter has pointer type, check for a null template value.
3691 // A template-argument for a non-type, non-template
3692 // template-parameter shall be one of: [...]
3696 // template-ids but excluding non-static class members,
3699 // corresponding template-parameter is a reference; or
3786 // A non-type template argument must refer to an object or function.
3795 // Address / reference template args must have external linkage in C++98.
3812 // If the template parameter has pointer type, the function decays.
3844 // A template argument must have static storage duration.
3853 // If the template parameter has pointer type, we must have taken
3880 // If the template parameter has pointer type but the address of
3911 // For a non-type template-parameter of type reference to
3914 // identical) type of the template- argument. The
3915 // template-parameter is bound directly to the
3916 // template-argument, which shall be an lvalue.
3933 // At this point, the template argument refers to an object or
3950 // Create the template argument.
3957 /// \brief Checks whether the given template argument is a pointer to
4001 // A template-argument for a non-type, non-template
4002 // template-parameter shall be one of: [...]
4085 /// \brief Check a template argument against its corresponding
4086 /// non-type template parameter.
4090 /// returns the converted template argument. \p
4091 /// InstantiatedParamType is the type of the non-type template
4109 // as a non-type template-argument. If a non-type
4110 // template-argument cannot be converted to the type of the
4111 // corresponding template-parameter then the program is
4116 // -- for a non-type template-parameter of integral or
4121 // -- for a non-type template-parameter of integral or
4128 // If, in the declaration of a function template with a non-type
4129 // template-parameter, the non-type template-parameter is used
4131 // corresponding template-argument is deduced, the
4132 // template-argument type shall match the type of the
4133 // template-parameter exactly, except that a template-argument
4144 // FIXME: If there's no viable conversion to the template parameter type,
4152 // A template-argument for a non-type, non-template template-parameter
4155 // -- for a non-type template-parameter of integral or enumeration
4157 // template-parameter; or
4186 // A template-argument for a non-type, non-template
4187 // template-parameter shall be one of:
4191 // -- the name of a non-type template-parameter; or
4244 // arguments. We use the bitwidth and signedness of the template
4267 // Coerce the template argument's value to the value it will have
4268 // based on the template parameter's type.
4283 // Complain if we overflowed the template parameter's type.
4312 if (// -- For a non-type template-parameter of type pointer to
4314 // applied. If the template-argument represents a set of
4319 // -- For a non-type template-parameter of type reference to
4320 // function, no conversions apply. If the template-argument
4325 // -- For a non-type template-parameter of type pointer to
4327 // template-argument represents a set of overloaded member
4362 // -- for a non-type template-parameter of type pointer to
4377 // -- For a non-type template-parameter of type reference to
4380 // identical) type of the template-argument. The
4381 // template-parameter is bound directly to the
4382 // template-argument, which must be an lvalue.
4431 // -- For a non-type template-parameter of type pointer to data
4441 /// \brief Check a template argument against its corresponding
4442 /// template template parameter.
4444 /// This routine implements the semantics of C++ [temp.arg.template].
4450 TemplateDecl *Template = Name.getAsTemplateDecl();
4451 if (!Template) {
4452 // Any dependent template name is fine.
4453 assert(Name.isDependent() && "Non-dependent template isn't a declaration?");
4457 // C++0x [temp.arg.template]p1:
4458 // A template-argument for a template template-parameter shall be
4459 // the name of a class template or an alias template, expressed as an
4460 // id-expression. When the template-argument names a class template, only
4462 // template template argument with the corresponding parameter;
4464 // parameter lists match that of the template template parameter.
4466 // Note that we also allow template template parameters here, which
4467 // will happen when we are dealing with, e.g., class template
4469 if (!isa<ClassTemplateDecl>(Template) &&
4470 !isa<TemplateTemplateParmDecl>(Template) &&
4471 !isa<TypeAliasTemplateDecl>(Template)) {
4472 assert(isa<FunctionTemplateDecl>(Template) &&
4475 Diag(Template->getLocation(), diag::note_template_arg_refers_here_func)
4476 << Template;
4483 return !TemplateParameterListsAreEqual(Template->getTemplateParameters(),
4490 /// \brief Given a non-type template argument that refers to a
4491 /// declaration and the type of its corresponding non-type template
4500 // A non-type template-parameter of type "array of T" or
4508 // For a NULL non-type template argument, return nullptr casted to the
4519 "Only declaration template arguments permitted here");
4526 // Determine whether the non-type template template parameter is of
4575 // When the non-type template parameter is a pointer, take the
4596 // If the non-type template parameter has reference type, qualify the
4612 /// integral template argument with the given source-location
4615 /// This routine takes care of the mapping from an integral template
4622 "Operation is only valid for integral template arguments");
4659 // non-type template parameters.
4668 /// \brief Match two template parameters within template parameter lists.
4673 // Check the actual kind (type, non-type, template).
4691 // However, if we are matching a template template argument to a
4692 // template template parameter, the template template parameter can have
4693 // a parameter pack where the template template argument does not.
4717 // For non-type template parameters, check the type of the parameter.
4722 // If we are matching a template template argument to a template
4723 // template parameter and one of the non-type template parameter types
4724 // is dependent, then we must wait until template instantiation time
4753 // For template template parameters, check the template parameter types.
4754 // The template parameter lists of template template
4771 /// \brief Diagnose a known arity mismatch when comparing template argument
4793 /// \brief Determine whether the given template parameter lists are
4796 /// \param New The new template parameter list, typically written in the
4797 /// source code as part of a new template declaration.
4799 /// \param Old The old template parameter list, typically found via
4800 /// name lookup of the template declared with this template parameter
4804 /// the template parameter lists are not equivalent.
4806 /// \param Kind describes how we are to match the template parameter lists.
4809 /// are actually checking the template parameter list of a template
4810 /// argument (New) against the template parameter list of its
4811 /// corresponding template template parameter (Old). We produce
4814 /// \returns True if the template parameter lists are equal, false
4830 // C++0x [temp.arg.template]p3:
4831 // A template-argument matches a template template-parameter (call it P)
4832 // when each of the template parameters in the template-parameter-list of
4833 // the template-argument's corresponding class template or alias template
4834 // (call it A) matches the corresponding template parameter in the
4835 // template-parameter-list of P. [...]
4859 // C++0x [temp.arg.template]p3:
4860 // [...] When P's template- parameter-list contains a template parameter
4861 // pack (14.5.3), the template parameter pack will match zero or more
4862 // template parameters or template parameter packs in the
4863 // template-parameter-list of A with the same type and form as the
4864 // template parameter pack in P (ignoring whether those template
4865 // parameters are template parameter packs).
4885 /// \brief Check whether a template can be declared within this scope.
4887 /// If the template declaration is valid in this scope, returns
4900 // A template-declaration can appear only as a namespace scope or
4919 /// \brief Determine what kind of template specialization the given declaration
4938 /// This routine determines whether a template specialization can be declared
4945 /// may be a kind of template (class template, function template, etc.) or
4946 /// a member of a class template (member function, static data member,
4955 /// a class template.
4988 // of which the template is a member, or, for member templates, in
4990 // template is a member. An explicit specialization of a member
4992 // template shall be declared in the namespace of which the class
4993 // template is a member. Such a declaration may also be a
5030 // A class template partial specialization may be declared or redeclared
5042 // the template is a member, or, for member templates, in the namespace
5043 // of which the enclosing class or enclosing class template is a member.
5045 // static data member of a class template shall be declared in the
5046 // namespace of which the class template is a member.
5050 // the specialized template.
5103 /// that checks non-type template partial specialization arguments.
5144 // Within the argument list of a class template partial
5147 // shall not involve a template parameter of the partial
5157 // -- The type of a template parameter corresponding to a
5173 /// \brief Check the non-type template arguments of a class template
5176 /// \param TemplateParams the template parameters of the primary class
5177 /// template.
5179 /// \param TemplateArgs the template arguments of the class template
5218 // store the location of the outermost template keyword in the declaration.
5222 // Find the class template we're specializing
5237 // Check the validity of the template headers that introduce this
5238 // template.
5264 // The template parameter list of a specialization shall not
5265 // contain default template argument values.
5303 << FixItHint::CreateInsertion(KWLoc, "template<> ");
5308 // original template.
5310 assert(Kind != TTK_Enum && "Invalid enum tag in class template spec!");
5323 // Translate the parser's template argument list in our AST format.
5329 // Check for unexpanded parameter packs in any of the template arguments.
5335 // Check that the template argument list is well-formed for this
5336 // template.
5342 // Find the class template (partial) specialization declaration that
5366 // FIXME: Template parameter list matters, too
5378 // Check whether we can declare a class template specialization in
5391 // Since the only prior class template specialization with these
5395 // the list of outer template parameters to reflect our new declaration.
5406 // Build the canonical type that describes the converted template
5407 // arguments of the class template partial specialization.
5418 // to the implicit argument list of the primary template.
5432 // Create a new class template partial specialization declaration node.
5461 // template specialization, make a note of that.
5465 // Check that all of the template parameters of the class template
5466 // partial specialization are deducible from the template
5467 // arguments. If not, this class template partial specialization
5494 // Create a new class template specialization declaration node for
5518 // If a template, a member template or the member of a class template is
5577 // Build the fully-sugared type for this class template
5583 // template arguments in the specialization.
5593 // A template explicit specialization is in the scope of the
5594 // namespace in which the template was defined.
5680 /// \brief Diagnose cases where we have an explicit template specialization
5681 /// before/after an explicit template instantiation, producing diagnostics
5741 // If a template, a member template or the member of a class template
5775 // For a given set of template parameters, if an explicit instantiation
5776 // of a template appears after a declaration of an explicit
5777 // specialization for that template, the explicit instantiation has no
5809 // For a given set of template parameters, if an explicit
5810 // instantiation of a template appears after a declaration of
5811 // an explicit specialization for that template, the explicit
5831 // For a given set of template parameters, if an explicit instantiation
5832 // of a template appears after a declaration of an explicit
5833 // specialization for that template, the explicit instantiation has no
5847 // For a given template and a given set of template-arguments,
5863 /// template specialization.
5865 /// The only possible way to get a dependent function template specialization
5869 /// template \<class T> void foo(T);
5870 /// template \<class T> class A {
5881 // Remove anything from Previous that isn't a function template in
5902 /// \brief Perform semantic analysis for the given function template
5906 /// explicit function template specialization. On successful completion,
5907 /// the function declaration \p FD will become a function template
5911 /// function template specialization.
5913 /// \param ExplicitTemplateArgs the explicitly-provided template arguments,
5924 // The set of function template specializations that could match this
5925 // explicit function template specialization.
5939 // When matching a constexpr member function template specialization
5940 // against the primary template, we don't yet know whether the
5942 // it will be a static member function until we know which template it
5943 // specializes), so adjust it now assuming it specializes this template.
5960 // A trailing template-argument can be left unspecified in the
5961 // template-id naming an explicit function template specialization
5963 // Perform template argument deduction to determine whether we may be
5964 // specializing this template.
5971 // FIXME: Template argument deduction failed; record why it failed, so
5982 // Find the most specialized function template.
5999 assert(SpecInfo && "Function template specialization info missing?");
6001 // Note: do not overwrite location info if previous template
6007 // function can differ from the template declaration with respect to
6028 // If a template, a member template or the member of a class template is
6050 // Turn the given function declaration into a function template
6051 // specialization, with the template arguments from the previous
6053 // Take copies of (semantic and syntactic) template argument lists.
6062 // The "previous declaration" for this function template specialization is
6063 // the prior function template specialization.
6069 /// \brief Perform semantic analysis for the given non-template member
6085 assert(!isa<TemplateDecl>(Member) && "Only for non-template members");
6169 // If a template, a member template or the member of a class template is
6272 // template. If the name declared in the explicit instantiation is an
6274 // namespace where its template is declared or, if that namespace is inline
6309 /// \brief Determine whether the given scope specifier has a template-id in it.
6316 // or a static data member of a class template specialization, the name of
6317 // the class template specialization in the qualified-id for the member
6318 // name shall be a simple-template-id.
6330 // Explicit instantiation of a class template specialization
6344 // Find the class template we're specializing
6350 // original template.
6353 "Invalid enum tag in class template explicit instantiation!");
6374 // Translate the parser's template argument list in our AST format.
6378 // Check that the template argument list is well-formed for this
6379 // template.
6385 // Find the class template specialization declaration that
6397 // namespace of its template. [...]
6419 // Since the only prior class template specialization with these
6422 // for the template name to reflect our new declaration.
6431 // Create a new class template specialization declaration node for
6454 // on the "canonical" representation used to store the template
6477 // Set the template specialization kind.
6483 // A definition of a class template or class member template
6485 // the class template or class member template.
6499 // Instantiate the members of this class template specialization.
6514 // Set the template specialization kind.
6519 // Explicit instantiation of a member class of a class template.
6561 // simple-template-id.
6578 // namespace of its template. [...]
6606 // A definition of a member class of a class template shall be in scope
6689 // [...] An explicit instantiation of a function template shall not use the
6718 // A [...] static data member of a class template can be explicitly
6720 // template.
6747 // or a static data member of a class template specialization, the name of
6748 // the class template specialization in the qualified-id for the member
6749 // name shall be a simple-template-id.
6781 // If the declarator is a template-id, translate the parser's template
6796 // A [...] function [...] can be explicitly instantiated from its template.
6797 // A member function [...] of a class template can be explicitly
6799 // template.
6834 // Find the most specialized function template specialization.
6887 // or a static data member of a class template specialization, the name of
6888 // the class template specialization in the qualified-id for the member
6889 // name shall be a simple-template-id.
6996 // Translate the parser's template argument list in our AST format.
7000 TemplateName Template = TemplateIn.get();
7001 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7002 // Construct a dependent template specialization type.
7003 assert(DTN && "dependent template has non-dependent name?");
7026 QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
7030 // Provide source-location information for the template specialization type.
7059 // ... within an explicitly-written template specialization...
7070 // ... which names a complete class template declaration...
7082 // Assume the first template argument is the condition.
7124 // If we're looking up 'type' within a template named 'enable_if', produce
7242 /// a class template (or class template partial specialization) that was parsed
7243 /// and constructed before we entered the scope of the class template (or
7249 /// template<typename T>
7255 /// template<typename T>
7297 /// \brief Rebuild the template parameters now that we know we're in a current
7308 // Rebuild the template parameter list of a template template parameter.
7318 // Rebuild the type of a non-type template parameter.
7337 /// template parameters to template arguments.