From a49cb4e4942d8b03bf9088fd43a11fc629a09c0c Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 29 Sep 2009 14:38:03 +0000 Subject: [PATCH] Slightly improve the semantics of extern templates for member functions of class templates llvm-svn: 83063 --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 5 ++-- clang/test/SemaTemplate/extern-templates.cpp | 26 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 90a03972cc15..9c96b33cd0e3 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/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/clang/test/SemaTemplate/extern-templates.cpp b/clang/test/SemaTemplate/extern-templates.cpp index 458957033ef0..6bdf283391f2 100644 --- a/clang/test/SemaTemplate/extern-templates.cpp +++ b/clang/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); +}