From: John McCall Date: Thu, 30 Jun 2011 00:42:27 +0000 (+0000) Subject: Document and check tighter assumptions about the TemplateName of a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1901dce8b1e78d0bf7072cccab695bd58c7eec21;p=clang Document and check tighter assumptions about the TemplateName of a TemplateSpecializationType. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134120 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index e280cb7c49..06daf24e30 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -3432,28 +3432,33 @@ public: static bool classof(const AutoType *T) { return true; } }; -/// \brief Represents the type of a template specialization as written -/// in the source code. +/// \brief Represents a type template specialization; the template +/// must be a class template, a type alias template, or a template +/// template parameter. A template which cannot be resolved to one of +/// these, e.g. because it is written with a dependent scope +/// specifier, is instead represented as a +/// @c DependentTemplateSpecializationType. /// -/// Template specialization types represent the syntactic form of a -/// template-id that refers to a type, e.g., @c vector. Some -/// template specialization types are syntactic sugar, whose canonical -/// type will point to some other type node that represents the -/// instantiation or class template specialization. For example, a -/// class template specialization type of @c vector will refer to -/// a tag type for the instantiation -/// @c std::vector>. +/// A non-dependent template specialization type is always "sugar", +/// typically for a @c RecordType. For example, a class template +/// specialization type of @c vector will refer to a tag type for +/// the instantiation @c std::vector> /// -/// Other template specialization types, for which the template name -/// is dependent, may be canonical types. These types are always -/// dependent. +/// Template specializations are dependent if either the template or +/// any of the template arguments are dependent, in which case the +/// type may also be canonical. /// -/// An instance of this type is followed by an array of TemplateArgument*s, -/// then, if the template specialization type is for a type alias template, -/// a QualType representing the non-canonical aliased type. +/// Instances of this type are allocated with a trailing array of +/// TemplateArguments, followed by a QualType representing the +/// non-canonical aliased type when the template is a type alias +/// template. class TemplateSpecializationType : public Type, public llvm::FoldingSetNode { - /// \brief The name of the template being specialized. + /// \brief The name of the template being specialized. This is + /// either a TemplateName::Template (in which case it is a + /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a + /// TypeAliasTemplateDecl*) or a + /// TemplateName::SubstTemplateTemplateParmPack. TemplateName Template; /// \brief - The number of template arguments named in this class diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 320e807dca..68c3eeb892 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1763,6 +1763,9 @@ TemplateSpecializationType(TemplateName T, Template(T), NumArgs(NumArgs) { assert(!T.getAsDependentTemplateName() && "Use DependentTemplateSpecializationType for dependent template-name"); + assert((T.getKind() == TemplateName::Template || + T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && + "Unexpected template name for TemplateSpecializationType"); assert((!Canon.isNull() || T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && "No canonical type for non-dependent class template specialization");