clang API Documentation

Defines | Functions
SemaTemplate.cpp File Reference
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/Template.h"
#include "clang/Sema/TemplateDeduction.h"
#include "TreeTransform.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/PartialDiagnostic.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; }

Functions

static NamedDeclisAcceptableTemplateName (ASTContext &Context, NamedDecl *Orig)
 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 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 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 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 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 TemplateSpecializationKind getTemplateSpecializationKind (Decl *D)
 Determine what kind of template specialization the given declaration is.
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 bool CheckNonTypeClassTemplatePartialSpecializationArgs (Sema &S, NonTypeTemplateParmDecl *Param, const TemplateArgument *Args, unsigned NumArgs)
 Subroutine of Sema::CheckClassTemplatePartialSpecializationArgs that checks non-type template partial specialization arguments.
static bool CheckClassTemplatePartialSpecializationArgs (Sema &S, TemplateParameterList *TemplateParams, SmallVectorImpl< TemplateArgument > &TemplateArgs)
 Check the non-type template arguments of a class template partial specialization according to C++ [temp.class.spec]p9.
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.

Define Documentation

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

Definition at line 3179 of file SemaTemplate.cpp.

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

Definition at line 3181 of file SemaTemplate.cpp.

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

Definition at line 3177 of file SemaTemplate.cpp.


Function Documentation

static bool CheckClassTemplatePartialSpecializationArgs ( Sema S,
TemplateParameterList TemplateParams,
SmallVectorImpl< TemplateArgument > &  TemplateArgs 
) [static]

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

Parameters:
TemplateParamsthe template parameters of the primary class template.
TemplateArgthe template arguments of the class template partial specialization.
Returns:
true if there was an error, false otherwise.

Definition at line 4882 of file SemaTemplate.cpp.

References CheckNonTypeClassTemplatePartialSpecializationArgs(), clang::TemplateParameterList::getParam(), Param, and clang::TemplateParameterList::size().

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

static bool CheckExplicitInstantiationScope ( Sema S,
NamedDecl D,
SourceLocation  InstLoc,
bool  WasQualifiedName 
) [static]
static bool CheckNonTypeClassTemplatePartialSpecializationArgs ( Sema S,
NonTypeTemplateParmDecl Param,
const TemplateArgument Args,
unsigned  NumArgs 
) [static]
static bool CheckTemplateArgumentAddressOfObjectOrFunction ( Sema S,
NonTypeTemplateParmDecl Param,
QualType  ParamType,
Expr ArgIn,
TemplateArgument Converted 
) [static]
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 4661 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::getLangOptions(), 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::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 1482 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 5357 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 1100 of file SemaTemplate.cpp.

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

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

static void DiagnoseTemplateParameterListArityMismatch ( Sema S,
TemplateParameterList New,
TemplateParameterList Old,
Sema::TemplateParameterListEqualKind  Kind,
SourceLocation  TemplateArgLoc 
) [static]
static bool DiagnoseUnexpandedParameterPacks ( Sema S,
TemplateTemplateParmDecl TTP 
) [static]
static SourceRange getRangeOfTypeInNestedNameSpecifier ( ASTContext Context,
QualType  T,
const CXXScopeSpec SS 
) [static]
static TemplateSpecializationKind getTemplateSpecializationKind ( Decl D) [static]
static NamedDecl* isAcceptableTemplateName ( ASTContext Context,
NamedDecl Orig 
) [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 46 of file SemaTemplate.cpp.

References clang::NamedDecl::getUnderlyingDecl().

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

static bool MatchTemplateParameterKind ( Sema S,
NamedDecl New,
NamedDecl Old,
bool  Complain,
Sema::TemplateParameterListEqualKind  Kind,
SourceLocation  TemplateArgLoc 
) [static]
static bool ScopeSpecifierHasTemplateId ( const CXXScopeSpec SS) [static]

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

Definition at line 5957 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 5347 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 2451 of file SemaTemplate.cpp.

References clang::NamedDecl::getDeclName(), clang::TemplateTypeParmDecl::getDefaultArgumentInfo(), clang::TemplateTypeParmDecl::getDefaultArgumentLoc(), clang::Sema::getTemplateInstantiationArgs(), clang::TypeSourceInfo::getType(), 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 2504 of file SemaTemplate.cpp.

References clang::NonTypeTemplateParmDecl::getDefaultArgument(), clang::Sema::getTemplateInstantiationArgs(), clang::TemplateArgumentList::OnStack, and clang::Sema::SubstExpr().

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 2550 of file SemaTemplate.cpp.

References clang::TemplateArgumentLoc::getArgument(), clang::TemplateArgument::getAsTemplate(), clang::TemplateTemplateParmDecl::getDefaultArgument(), clang::Sema::getTemplateInstantiationArgs(), clang::TemplateArgumentLoc::getTemplateNameLoc(), clang::TemplateArgumentLoc::getTemplateQualifierLoc(), clang::TemplateArgumentList::OnStack, clang::Sema::SubstNestedNameSpecifierLoc(), and clang::Sema::SubstTemplateName().

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