clang API Documentation

Defines | Enumerations | Functions
SemaTemplate.cpp File Reference
#include "TreeTransform.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Template.h"
#include "clang/Sema/TemplateDeduction.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "clang/AST/TypeNodes.def"
Include dependency graph for SemaTemplate.cpp:

Go to the source code of this file.

Defines

#define TYPE(Class, Parent)   bool Visit##Class##Type(const Class##Type *);
#define ABSTRACT_TYPE(Class, Parent)   bool Visit##Class##Type(const Class##Type *) { return false; }
#define NON_CANONICAL_TYPE(Class, Parent)   bool Visit##Class##Type(const Class##Type *) { return false; }

Enumerations

enum  NullPointerValueKind { NPV_NotNullPointer, NPV_NullPointer, NPV_Error }

Functions

static NamedDeclisAcceptableTemplateName (ASTContext &Context, NamedDecl *Orig, bool AllowFunctionTemplates)
 Determine whether the declaration found is acceptable as the name of a template and, if so, return that template declaration. Otherwise, returns NULL.
static TemplateArgumentLoc translateTemplateArgument (Sema &SemaRef, const ParsedTemplateArgument &Arg)
static void maybeDiagnoseTemplateParameterShadow (Sema &SemaRef, Scope *S, SourceLocation Loc, IdentifierInfo *Name)
static void SetNestedNameSpecifier (TagDecl *T, const CXXScopeSpec &SS)
static bool DiagnoseDefaultTemplateArgument (Sema &S, Sema::TemplateParamListContext TPC, SourceLocation ParamLoc, SourceRange DefArgRange)
 Diagnose the presence of a default template argument on a template parameter, which is ill-formed in certain contexts.
static bool DiagnoseUnexpandedParameterPacks (Sema &S, TemplateTemplateParmDecl *TTP)
 Check for unexpanded parameter packs within the template parameters of a template template parameter, recursively.
static bool DependsOnTemplateParameters (QualType T, TemplateParameterList *Params)
static SourceRange getRangeOfTypeInNestedNameSpecifier (ASTContext &Context, QualType T, const CXXScopeSpec &SS)
static bool CheckTemplatePartialSpecializationArgs (Sema &S, SourceLocation TemplateNameLoc, TemplateParameterList *TemplateParams, unsigned NumExplicit, SmallVectorImpl< TemplateArgument > &TemplateArgs)
 Check the non-type template arguments of a class template partial specialization according to C++ [temp.class.spec]p9.
static bool CheckTemplateSpecializationScope (Sema &S, NamedDecl *Specialized, NamedDecl *PrevDecl, SourceLocation Loc, bool IsPartialSpecialization)
 Check whether a specialization is well-formed in the current context.
static TemplateSpecializationKind getTemplateSpecializationKind (Decl *D)
 Determine what kind of template specialization the given declaration is.
static bool isTemplateArgumentTemplateParameter (const TemplateArgument &Arg, unsigned Depth, unsigned Index)
static bool isSameAsPrimaryTemplate (TemplateParameterList *Params, ArrayRef< TemplateArgument > Args)
static TemplateArgumentListInfo makeTemplateArgumentListInfo (Sema &S, TemplateIdAnnotation &TemplateId)
 Convert the parser's template argument list representation into our form.
static TypeSourceInfoSubstDefaultTemplateArgument (Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, TemplateTypeParmDecl *Param, SmallVectorImpl< TemplateArgument > &Converted)
 Substitute template arguments into the default template argument for the given template type parameter.
static ExprResult SubstDefaultTemplateArgument (Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, NonTypeTemplateParmDecl *Param, SmallVectorImpl< TemplateArgument > &Converted)
 Substitute template arguments into the default template argument for the given non-type template parameter.
static TemplateName SubstDefaultTemplateArgument (Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, TemplateTemplateParmDecl *Param, SmallVectorImpl< TemplateArgument > &Converted, NestedNameSpecifierLoc &QualifierLoc)
 Substitute template arguments into the default template argument for the given template template parameter.
static bool diagnoseArityMismatch (Sema &S, TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
 Diagnose an arity mismatch in the.
static Optional< unsignedgetExpandedPackSize (NamedDecl *Param)
 Check whether the template parameter is a pack expansion, and if so, determine the number of parameters produced by that expansion. For instance:
static NullPointerValueKind isNullPointerValueTemplateArgument (Sema &S, NonTypeTemplateParmDecl *Param, QualType ParamType, Expr *Arg)
 Determine whether the given template argument is a null pointer value of the appropriate type.
static bool CheckTemplateArgumentIsCompatibleWithParameter (Sema &S, NonTypeTemplateParmDecl *Param, QualType ParamType, Expr *ArgIn, Expr *Arg, QualType ArgType)
 Checks whether the given template argument is compatible with its template parameter.
static bool CheckTemplateArgumentAddressOfObjectOrFunction (Sema &S, NonTypeTemplateParmDecl *Param, QualType ParamType, Expr *ArgIn, TemplateArgument &Converted)
 Checks whether the given template argument is the address of an object or function according to C++ [temp.arg.nontype]p1.
static bool CheckTemplateArgumentPointerToMember (Sema &S, NonTypeTemplateParmDecl *Param, QualType ParamType, Expr *&ResultArg, TemplateArgument &Converted)
 Checks whether the given template argument is a pointer to member constant according to C++ [temp.arg.nontype]p1.
static bool MatchTemplateParameterKind (Sema &S, NamedDecl *New, NamedDecl *Old, bool Complain, Sema::TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc)
 Match two template parameters within template parameter lists.
static void DiagnoseTemplateParameterListArityMismatch (Sema &S, TemplateParameterList *New, TemplateParameterList *Old, Sema::TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc)
 Diagnose a known arity mismatch when comparing template argument lists.
static SourceRange findTemplateParameter (unsigned Depth, Expr *E)
static SourceRange findTemplateParameter (unsigned Depth, TypeLoc TL)
static bool CheckNonTypeTemplatePartialSpecializationArgs (Sema &S, SourceLocation TemplateNameLoc, NonTypeTemplateParmDecl *Param, const TemplateArgument *Args, unsigned NumArgs, bool IsDefaultArgument)
 Subroutine of Sema::CheckTemplatePartialSpecializationArgs that checks non-type template partial specialization arguments.
static void StripImplicitInstantiation (NamedDecl *D)
 Strips various properties off an implicit instantiation that has just been explicitly specialized.
static SourceLocation DiagLocForExplicitInstantiation (NamedDecl *D, SourceLocation PointOfInstantiation)
 Compute the diagnostic location for an explicit instantiation.
static bool CheckExplicitInstantiationScope (Sema &S, NamedDecl *D, SourceLocation InstLoc, bool WasQualifiedName)
 Check the scope of an explicit instantiation.
static bool ScopeSpecifierHasTemplateId (const CXXScopeSpec &SS)
 Determine whether the given scope specifier has a template-id in it.
static bool isEnableIf (NestedNameSpecifierLoc NNS, const IdentifierInfo &II, SourceRange &CondRange)

Define Documentation

#define ABSTRACT_TYPE (   Class,
  Parent 
)    bool Visit##Class##Type(const Class##Type *) { return false; }

Definition at line 3902 of file SemaTemplate.cpp.

#define NON_CANONICAL_TYPE (   Class,
  Parent 
)    bool Visit##Class##Type(const Class##Type *) { return false; }

Definition at line 3904 of file SemaTemplate.cpp.

#define TYPE (   Class,
  Parent 
)    bool Visit##Class##Type(const Class##Type *);

Definition at line 3900 of file SemaTemplate.cpp.


Enumeration Type Documentation

Enumerator:
NPV_NotNullPointer 
NPV_NullPointer 
NPV_Error 

Definition at line 4165 of file SemaTemplate.cpp.


Function Documentation

static bool CheckExplicitInstantiationScope ( Sema S,
NamedDecl D,
SourceLocation  InstLoc,
bool  WasQualifiedName 
) [static]
static bool CheckNonTypeTemplatePartialSpecializationArgs ( Sema S,
SourceLocation  TemplateNameLoc,
NonTypeTemplateParmDecl Param,
const TemplateArgument Args,
unsigned  NumArgs,
bool  IsDefaultArgument 
) [static]
static bool CheckTemplateArgumentAddressOfObjectOrFunction ( Sema S,
NonTypeTemplateParmDecl Param,
QualType  ParamType,
Expr ArgIn,
TemplateArgument Converted 
) [static]
static bool CheckTemplateArgumentIsCompatibleWithParameter ( Sema S,
NonTypeTemplateParmDecl Param,
QualType  ParamType,
Expr ArgIn,
Expr Arg,
QualType  ArgType 
) [static]
static bool CheckTemplateArgumentPointerToMember ( Sema S,
NonTypeTemplateParmDecl Param,
QualType  ParamType,
Expr *&  ResultArg,
TemplateArgument Converted 
) [static]
static bool CheckTemplatePartialSpecializationArgs ( Sema S,
SourceLocation  TemplateNameLoc,
TemplateParameterList TemplateParams,
unsigned  NumExplicit,
SmallVectorImpl< TemplateArgument > &  TemplateArgs 
) [static]

Check the non-type template arguments of a class template partial specialization according to C++ [temp.class.spec]p9.

Parameters:
TemplateNameLocthe location of the template name.
TemplateParamsthe template parameters of the primary class template.
NumExplicitthe number of explicitly-specified template arguments.
TemplateArgsthe template arguments of the class template partial specialization.
Returns:
true if there was an error, false otherwise.

Definition at line 5899 of file SemaTemplate.cpp.

References CheckNonTypeTemplatePartialSpecializationArgs(), clang::TemplateParameterList::getParam(), and clang::TemplateParameterList::size().

Referenced by clang::Sema::ActOnClassTemplateSpecialization(), and clang::Sema::ActOnVarTemplateSpecialization().

static bool CheckTemplateSpecializationScope ( Sema S,
NamedDecl Specialized,
NamedDecl PrevDecl,
SourceLocation  Loc,
bool  IsPartialSpecialization 
) [static]

Check whether a specialization is well-formed in the current context.

This routine determines whether a template specialization can be declared in the current context (C++ [temp.expl.spec]p2).

Parameters:
Sthe semantic analysis object for which this check is being performed.
Specializedthe entity being specialized or instantiated, which may be a kind of template (class template, function template, etc.) or a member of a class template (member function, static data member, member class).
PrevDeclthe previous declaration of this entity, if any.
Locthe location of the explicit specialization or instantiation of this entity.
IsPartialSpecializationwhether this is a partial specialization of a class template.
Returns:
true if there was an error that we cannot recover from, false otherwise.

Definition at line 5630 of file SemaTemplate.cpp.

References clang::Sema::ActiveTemplateInstantiations, clang::Sema::CurContext, Diag(), clang::Sema::Diag(), clang::DeclContext::Encloses(), clang::DeclContext::Equals(), clang::Decl::getDeclContext(), clang::DeclContext::getEnclosingNamespaceContext(), clang::Sema::getLangOpts(), clang::Decl::getLocation(), clang::DeclContext::getRedeclContext(), getTemplateSpecializationKind(), clang::DeclContext::InEnclosingNamespaceSetOf(), clang::DeclContext::isFunctionOrMethod(), clang::DeclContext::isRecord(), clang::TSK_ImplicitInstantiation, and clang::TSK_Undeclared.

Referenced by clang::Sema::ActOnClassTemplateSpecialization(), clang::Sema::ActOnVarTemplateSpecialization(), clang::Sema::CheckFunctionTemplateSpecialization(), and clang::Sema::CheckMemberSpecialization().

static bool DependsOnTemplateParameters ( QualType  T,
TemplateParameterList Params 
) [static]

Determines whether a given type depends on the given parameter list.

Definition at line 1556 of file SemaTemplate.cpp.

Referenced by clang::Sema::MatchTemplateParametersToScopeSpecifier().

static SourceLocation DiagLocForExplicitInstantiation ( NamedDecl D,
SourceLocation  PointOfInstantiation 
) [static]

Compute the diagnostic location for an explicit instantiation.

Definition at line 6348 of file SemaTemplate.cpp.

References clang::SourceLocation::isValid().

Referenced by clang::Sema::CheckSpecializationInstantiationRedecl().

static bool diagnoseArityMismatch ( Sema S,
TemplateDecl Template,
SourceLocation  TemplateLoc,
TemplateArgumentListInfo TemplateArgs 
) [static]
static bool DiagnoseDefaultTemplateArgument ( Sema S,
Sema::TemplateParamListContext  TPC,
SourceLocation  ParamLoc,
SourceRange  DefArgRange 
) [static]

Diagnose the presence of a default template argument on a template parameter, which is ill-formed in certain contexts.

Returns:
true if the default template argument should be dropped.

Definition at line 1150 of file SemaTemplate.cpp.

References clang::Sema::Diag(), clang::Sema::getLangOpts(), clang::Sema::TPC_ClassTemplate, clang::Sema::TPC_ClassTemplateMember, clang::Sema::TPC_FriendClassTemplate, clang::Sema::TPC_FriendFunctionTemplate, clang::Sema::TPC_FriendFunctionTemplateDefinition, clang::Sema::TPC_FunctionTemplate, clang::Sema::TPC_TypeAliasTemplate, and clang::Sema::TPC_VarTemplate.

Referenced by clang::Sema::CheckTemplateParameterList().

static SourceRange findTemplateParameter ( unsigned  Depth,
Expr E 
) [static]
static SourceRange findTemplateParameter ( unsigned  Depth,
TypeLoc  TL 
) [static]
static Optional<unsigned> getExpandedPackSize ( NamedDecl Param) [static]

Check whether the template parameter is a pack expansion, and if so, determine the number of parameters produced by that expansion. For instance:

 template<typename ...Ts> struct A {
   template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
 };

In A<int,int>::B, NTs and TTs have expanded pack size 2, and Us is not a pack expansion, so returns an empty Optional.

Definition at line 3623 of file SemaTemplate.cpp.

Referenced by clang::Sema::CheckTemplateArgumentList().

static SourceRange getRangeOfTypeInNestedNameSpecifier ( ASTContext Context,
QualType  T,
const CXXScopeSpec SS 
) [static]
static NamedDecl* isAcceptableTemplateName ( ASTContext Context,
NamedDecl Orig,
bool  AllowFunctionTemplates 
) [static]

Determine whether the declaration found is acceptable as the name of a template and, if so, return that template declaration. Otherwise, returns NULL.

Definition at line 48 of file SemaTemplate.cpp.

References clang::NamedDecl::getUnderlyingDecl(), and Record.

Referenced by clang::Sema::FilterAcceptableTemplateNames(), and clang::Sema::hasAnyAcceptableTemplateNames().

static bool isEnableIf ( NestedNameSpecifierLoc  NNS,
const IdentifierInfo II,
SourceRange CondRange 
) [static]
static NullPointerValueKind isNullPointerValueTemplateArgument ( Sema S,
NonTypeTemplateParmDecl Param,
QualType  ParamType,
Expr Arg 
) [static]
static bool isSameAsPrimaryTemplate ( TemplateParameterList Params,
ArrayRef< TemplateArgument Args 
) [static]
static bool isTemplateArgumentTemplateParameter ( const TemplateArgument Arg,
unsigned  Depth,
unsigned  Index 
) [static]
static bool MatchTemplateParameterKind ( Sema S,
NamedDecl New,
NamedDecl Old,
bool  Complain,
Sema::TemplateParameterListEqualKind  Kind,
SourceLocation  TemplateArgLoc 
) [static]
static void maybeDiagnoseTemplateParameterShadow ( Sema SemaRef,
Scope S,
SourceLocation  Loc,
IdentifierInfo Name 
) [static]
static bool ScopeSpecifierHasTemplateId ( const CXXScopeSpec SS) [static]

Determine whether the given scope specifier has a template-id in it.

Definition at line 7002 of file SemaTemplate.cpp.

References clang::NestedNameSpecifier::getAsType(), clang::NestedNameSpecifier::getPrefix(), clang::CXXScopeSpec::getScopeRep(), and clang::CXXScopeSpec::isSet().

Referenced by clang::Sema::ActOnExplicitInstantiation().

static void SetNestedNameSpecifier ( TagDecl T,
const CXXScopeSpec SS 
) [static]
static void StripImplicitInstantiation ( NamedDecl D) [static]

Strips various properties off an implicit instantiation that has just been explicitly specialized.

Definition at line 6335 of file SemaTemplate.cpp.

References clang::Decl::dropAttrs().

Referenced by clang::Sema::CheckSpecializationInstantiationRedecl().

static TypeSourceInfo* SubstDefaultTemplateArgument ( Sema SemaRef,
TemplateDecl Template,
SourceLocation  TemplateLoc,
SourceLocation  RAngleLoc,
TemplateTypeParmDecl Param,
SmallVectorImpl< TemplateArgument > &  Converted 
) [static]

Substitute template arguments into the default template argument for the given template type parameter.

Parameters:
SemaRefthe semantic analysis object for which we are performing the substitution.
Templatethe template that we are synthesizing template arguments for.
TemplateLocthe location of the template name that started the template-id we are checking.
RAngleLocthe location of the right angle bracket ('>') that terminates the template-id.
Paramthe template template parameter whose default we are substituting into.
Convertedthe list of template arguments provided for template parameters that precede Param in the template parameter list.
Returns:
the substituted template argument, or NULL if an error occurred.

Definition at line 3139 of file SemaTemplate.cpp.

References clang::MultiLevelTemplateArgumentList::addOuterTemplateArguments(), clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::TemplateTypeParmDecl::getDefaultArgumentInfo(), clang::TemplateTypeParmDecl::getDefaultArgumentLoc(), clang::TemplateTypeParmDecl::getDepth(), clang::TypeSourceInfo::getType(), clang::Type::isDependentType(), clang::Sema::InstantiatingTemplate::isInvalid(), clang::TemplateArgumentList::OnStack, and clang::Sema::SubstType().

Referenced by clang::Sema::CheckTemplateArgumentList(), and clang::Sema::SubstDefaultTemplateArgumentIfAvailable().

static ExprResult SubstDefaultTemplateArgument ( Sema SemaRef,
TemplateDecl Template,
SourceLocation  TemplateLoc,
SourceLocation  RAngleLoc,
NonTypeTemplateParmDecl Param,
SmallVectorImpl< TemplateArgument > &  Converted 
) [static]

Substitute template arguments into the default template argument for the given non-type template parameter.

Parameters:
SemaRefthe semantic analysis object for which we are performing the substitution.
Templatethe template that we are synthesizing template arguments for.
TemplateLocthe location of the template name that started the template-id we are checking.
RAngleLocthe location of the right angle bracket ('>') that terminates the template-id.
Paramthe non-type template parameter whose default we are substituting into.
Convertedthe list of template arguments provided for template parameters that precede Param in the template parameter list.
Returns:
the substituted template argument, or NULL if an error occurred.

Definition at line 3197 of file SemaTemplate.cpp.

References clang::MultiLevelTemplateArgumentList::addOuterTemplateArguments(), clang::ExprError(), clang::Decl::getDeclContext(), clang::NonTypeTemplateParmDecl::getDefaultArgument(), clang::TemplateParmPosition::getDepth(), clang::Sema::InstantiatingTemplate::isInvalid(), clang::TemplateArgumentList::OnStack, clang::Sema::SubstExpr(), and clang::Sema::Unevaluated.

static TemplateName SubstDefaultTemplateArgument ( Sema SemaRef,
TemplateDecl Template,
SourceLocation  TemplateLoc,
SourceLocation  RAngleLoc,
TemplateTemplateParmDecl Param,
SmallVectorImpl< TemplateArgument > &  Converted,
NestedNameSpecifierLoc QualifierLoc 
) [static]

Substitute template arguments into the default template argument for the given template template parameter.

Parameters:
SemaRefthe semantic analysis object for which we are performing the substitution.
Templatethe template that we are synthesizing template arguments for.
TemplateLocthe location of the template name that started the template-id we are checking.
RAngleLocthe location of the right angle bracket ('>') that terminates the template-id.
Paramthe template template parameter whose default we are substituting into.
Convertedthe list of template arguments provided for template parameters that precede Param in the template parameter list.
QualifierLocWill be set to the nested-name-specifier (with source-location information) that precedes the template name.
Returns:
the substituted template argument, or NULL if an error occurred.

Definition at line 3249 of file SemaTemplate.cpp.

References clang::MultiLevelTemplateArgumentList::addOuterTemplateArguments(), clang::TemplateArgumentLoc::getArgument(), clang::TemplateArgument::getAsTemplate(), clang::Decl::getDeclContext(), clang::TemplateTemplateParmDecl::getDefaultArgument(), clang::TemplateParmPosition::getDepth(), clang::TemplateArgumentLoc::getTemplateNameLoc(), clang::TemplateArgumentLoc::getTemplateQualifierLoc(), clang::Sema::InstantiatingTemplate::isInvalid(), clang::TemplateArgumentList::OnStack, clang::Sema::SubstNestedNameSpecifierLoc(), and clang::Sema::SubstTemplateName().

static TemplateArgumentLoc translateTemplateArgument ( Sema SemaRef,
const ParsedTemplateArgument Arg 
) [static]