From: Douglas Gregor Date: Tue, 29 Sep 2009 14:38:03 +0000 (+0000) Subject: Slightly improve the semantics of extern templates for member functions of class... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=483168227946f70e9dd7d12e7bf72bb1d76e0740;p=clang 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 --- 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(*D)) { - if (!Function->getBody()) + if (!Function->getBody() && TSK != TSK_ExplicitInstantiationDeclaration) InstantiateFunctionDefinition(PointOfInstantiation, Function); } else if (VarDecl *Var = dyn_cast(*D)) { - if (Var->isStaticDataMember()) + if (Var->isStaticDataMember() && + TSK != TSK_ExplicitInstantiationDeclaration) InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var); } else if (CXXRecordDecl *Record = dyn_cast(*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 xl, X0::Inner xli) { } template class X0; + +template +class X1 { +public: + void f(T t) { t += 2; } + + void g(T t); +}; + +template +void X1::g(T t) { + t += 2; +} + +extern template class X1; + +void g_X1(X1 x1, void *ptr) { + x1.g(ptr); +} + +extern template void X1::g(const void*); + +void g_X1_2(X1 x1, const void *ptr) { + // FIXME: This should not instantiate of x1::g +// x1.g(ptr); +}