//===------- SemaTemplate.cpp - Semantic Analysis for C++ Templates -------===/
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//+//===----------------------------------------------------------------------===/
//
// This file implements semantic analysis for C++ templates.
//+//===----------------------------------------------------------------------===/
#include "Sema.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Basic/LangOptions.h"
using namespace clang;
/// isTemplateName - Determines whether the identifier II is a
/// template name in the current scope, and returns the template
/// declaration if II names a template. An optional CXXScope can be
/// passed to indicate the C++ scope in which the identifier will be
/// found.
Sema::TemplateNameKind Sema::isTemplateName(IdentifierInfo &II, Scope *S,
DeclTy *&Template,
const CXXScopeSpec *SS) {
NamedDecl *IIDecl = LookupParsedName(S, SS, &II, LookupOrdinaryName);
if (IIDecl) {
if (isa<TemplateDecl>(IIDecl)) {
Template = IIDecl;
if (isa<FunctionTemplateDecl>(IIDecl))
return TNK_Function_template;
else if (isa<ClassTemplateDecl>(IIDecl))
return TNK_Class_template;
else if (isa<TemplateTemplateParmDecl>(IIDecl))
return TNK_Template_template_parm;
else
assert(false && "Unknown TemplateDecl");
}
// FIXME: What follows is a gross hack.
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(IIDecl)) {
if (FD->getType()->isDependentType()) {
Template = FD;
return TNK_Function_template;
}
} else if (OverloadedFunctionDecl *Ovl
= dyn_cast<OverloadedFunctionDecl>(IIDecl)) {
for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin