[cfe-commits] r81515 - in /cfe/trunk: include/clang/AST/DeclTemplate.h lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaType.cpp test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp test/SemaTemplate/temp_class_spec.cpp
John McCall
rjmccall at apple.com
Fri Sep 11 00:25:08 PDT 2009
Author: rjmccall
Date: Fri Sep 11 02:25:08 2009
New Revision: 81515
URL: http://llvm.org/viewvc/llvm-project?rev=81515&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
cfe/trunk/test/SemaTemplate/temp_class_spec.cpp
Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Fri Sep 11 02:25:08 2009
@@ -906,6 +906,9 @@
/// \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 @@
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
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Sep 11 02:25:08 2009
@@ -1097,7 +1097,7 @@
// 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 @@
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
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Fri Sep 11 02:25:08 2009
@@ -895,7 +895,7 @@
// Note that this is an instantiation.
ClassTemplateSpec->setSpecializationKind(TSK);
- bool Result = InstantiateClass(ClassTemplateSpec->getLocation(),
+ bool Result = InstantiateClass(ClassTemplateSpec->getPointOfInstantiation(),
ClassTemplateSpec, Pattern,
getTemplateInstantiationArgs(ClassTemplateSpec),
TSK,
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Sep 11 02:25:08 2009
@@ -1784,10 +1784,8 @@
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);
Modified: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp Fri Sep 11 02:25:08 2009
@@ -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;
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp Fri Sep 11 02:25:08 2009
@@ -16,7 +16,7 @@
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 @@
};
};
-// 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
Modified: cfe/trunk/test/SemaTemplate/temp_class_spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_class_spec.cpp?rev=81515&r1=81514&r2=81515&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_class_spec.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_class_spec.cpp Fri Sep 11 02:25:08 2009
@@ -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 @@
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 {
More information about the cfe-commits
mailing list