diff options
-rw-r--r-- | include/clang/AST/DeclTemplate.h | 13 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 4 | ||||
-rw-r--r-- | test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp | 6 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp | 5 | ||||
-rw-r--r-- | test/SemaTemplate/temp_class_spec.cpp | 5 |
7 files changed, 24 insertions, 15 deletions
diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index ced7639f87..2b232f1e28 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -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 diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 63c29de82b..8bb33eb985 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -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 diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index e719bbde92..6a5235229a 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -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, diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 9f951989a7..bbcb1a4689 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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); diff --git a/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp b/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp index 5346f36739..cb9d942ba6 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp @@ -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; diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp index b76cb91a75..89f938d1f7 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp @@ -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 diff --git a/test/SemaTemplate/temp_class_spec.cpp b/test/SemaTemplate/temp_class_spec.cpp index e625009c46..cf206d162f 100644 --- a/test/SemaTemplate/temp_class_spec.cpp +++ b/test/SemaTemplate/temp_class_spec.cpp @@ -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 { |