Track a class template specialization's point of instantiation separately

from its location.  Initialize appropriately.

When implicitly creating a declaration of a class template specialization
after encountering the first reference to it, use the pattern class's
location instead of the location of the first reference.

llvm-svn: 81515
This commit is contained in:
John McCall 2009-09-11 07:25:08 +00:00
parent 19a9f42f20
commit 1806c2795b
7 changed files with 24 additions and 15 deletions

View File

@ -906,6 +906,9 @@ class ClassTemplateSpecializationDecl
/// \brief The template arguments used to describe this specialization.
TemplateArgumentList TemplateArgs;
/// \brief The point where this template was instantiated (if any)
SourceLocation PointOfInstantiation;
/// \brief The kind of specialization this declaration refers to.
/// Really a value of type TemplateSpecializationKind.
unsigned SpecializationKind : 3;
@ -949,6 +952,16 @@ public:
SpecializationKind = TSK;
}
/// \brief Get the point of instantiation (if any), or null if none.
SourceLocation getPointOfInstantiation() const {
return PointOfInstantiation;
}
void setPointOfInstantiation(SourceLocation Loc) {
assert(Loc.isValid() && "point of instantiation must be valid!");
PointOfInstantiation = Loc;
}
/// \brief If this class template specialization is an instantiation of
/// a template (rather than an explicit specialization), return the
/// class template or class template partial specialization from which it

View File

@ -1097,7 +1097,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// the set of specializations.
Decl = ClassTemplateSpecializationDecl::Create(Context,
ClassTemplate->getDeclContext(),
TemplateLoc,
ClassTemplate->getLocation(),
ClassTemplate,
Converted, 0);
ClassTemplate->getSpecializations().InsertNode(Decl, InsertPos);
@ -3027,6 +3027,8 @@ Sema::ActOnExplicitInstantiation(Scope *S,
Specialization->setLexicalDeclContext(CurContext);
CurContext->addDecl(Specialization);
Specialization->setPointOfInstantiation(TemplateNameLoc);
// C++ [temp.explicit]p3:
// A definition of a class template or class member template
// shall be in scope at the point of the explicit instantiation of

View File

@ -895,7 +895,7 @@ Sema::InstantiateClassTemplateSpecialization(
// Note that this is an instantiation.
ClassTemplateSpec->setSpecializationKind(TSK);
bool Result = InstantiateClass(ClassTemplateSpec->getLocation(),
bool Result = InstantiateClass(ClassTemplateSpec->getPointOfInstantiation(),
ClassTemplateSpec, Pattern,
getTemplateInstantiationArgs(ClassTemplateSpec),
TSK,

View File

@ -1784,10 +1784,8 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
if (ClassTemplateSpecializationDecl *ClassTemplateSpec
= dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl())) {
if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared) {
// Update the class template specialization's location to
// refer to the point of instantiation.
if (Loc.isValid())
ClassTemplateSpec->setLocation(Loc);
ClassTemplateSpec->setPointOfInstantiation(Loc);
return InstantiateClassTemplateSpecialization(ClassTemplateSpec,
TSK_ImplicitInstantiation,
/*Complain=*/diag != 0);

View File

@ -5,15 +5,13 @@
// Tests that this form is accepted by the compiler but does not follow
// the elaborated lookup rules of [basic.lookup.elab].
template <typename> class Ident {};
template <typename> class Ident {}; // expected-note {{previous use is here}}
namespace A {
template <typename> void Ident();
class Ident<int> AIdent; // expected-error {{refers to a function template}}
// FIXME: this note should be on the template declaration, not the point of instantiation
class ::Ident<int> AnotherIdent; // expected-note {{previous use is here}}
class ::Ident<int> AnotherIdent;
}
class Ident<int> GlobalIdent;

View File

@ -16,7 +16,7 @@ class A1 {
friend enum A; // expected-error {{ISO C++ forbids forward references to 'enum' types}}
};
template <class T> struct B {
template <class T> struct B { // expected-note {{previous use is here}}
class Member {}; // expected-note 2 {{previous use is here}}
};
@ -31,8 +31,7 @@ template <> struct B<A> {
};
};
// FIXME: this note should be on the template declaration, not the point of instantiation
void b1(struct B<float>); // expected-note {{previous use is here}}
void b1(struct B<float>);
void b2(class B<float>);
void b3(union B<float>); // expected-error {{use of 'B<float>' with tag type that does not match previous declaration}}
//void b4(enum B<float>); // this just doesn't parse; you can't template an enum directly

View File

@ -1,6 +1,6 @@
// RUN: clang-cc -fsyntax-only -verify %s
template<typename T>
struct is_pointer {
struct is_pointer { // expected-error{{partial ordering}}
static const bool value = false;
};
@ -16,8 +16,7 @@ struct is_pointer<const T*> {
int array0[is_pointer<int>::value? -1 : 1];
int array1[is_pointer<int*>::value? 1 : -1];
int array2[is_pointer<const int*>::value? 1 : -1]; // expected-error{{partial ordering}} \
// expected-error{{negative}}
int array2[is_pointer<const int*>::value? 1 : -1]; // expected-error{{negative}}
template<typename T>
struct is_lvalue_reference {