aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-29 14:38:03 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-29 14:38:03 +0000
commit483168227946f70e9dd7d12e7bf72bb1d76e0740 (patch)
treea33ec8b790f6cfb00576b74b56987903d96cf8b3
parent9e17cc6abb5d55bd776d379b20d5b476bcc46c71 (diff)
Slightly improve the semantics of extern templates for member functions of class templates
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83063 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp5
-rw-r--r--test/SemaTemplate/extern-templates.cpp26
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 90a03972cc..9c96b33cd0 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -977,10 +977,11 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
DEnd = Instantiation->decls_end();
D != DEnd; ++D) {
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) {
- if (!Function->getBody())
+ if (!Function->getBody() && TSK != TSK_ExplicitInstantiationDeclaration)
InstantiateFunctionDefinition(PointOfInstantiation, Function);
} else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) {
- if (Var->isStaticDataMember())
+ if (Var->isStaticDataMember() &&
+ TSK != TSK_ExplicitInstantiationDeclaration)
InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var);
} else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) {
if (!Record->isInjectedClassName() && !Record->getDefinition(Context)) {
diff --git a/test/SemaTemplate/extern-templates.cpp b/test/SemaTemplate/extern-templates.cpp
index 458957033e..6bdf283391 100644
--- a/test/SemaTemplate/extern-templates.cpp
+++ b/test/SemaTemplate/extern-templates.cpp
@@ -39,3 +39,29 @@ void test_longptr(X0<long*> xl, X0<long*>::Inner xli) {
}
template class X0<long*>;
+
+template<typename T>
+class X1 {
+public:
+ void f(T t) { t += 2; }
+
+ void g(T t);
+};
+
+template<typename T>
+void X1<T>::g(T t) {
+ t += 2;
+}
+
+extern template class X1<void*>;
+
+void g_X1(X1<void*> x1, void *ptr) {
+ x1.g(ptr);
+}
+
+extern template void X1<const void*>::g(const void*);
+
+void g_X1_2(X1<const void *> x1, const void *ptr) {
+ // FIXME: This should not instantiate of x1<const void*>::g
+// x1.g(ptr);
+}