[cfe-commits] r83063 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/extern-templates.cpp

Douglas Gregor dgregor at apple.com
Tue Sep 29 07:38:04 PDT 2009


Author: dgregor
Date: Tue Sep 29 09:38:03 2009
New Revision: 83063

URL: http://llvm.org/viewvc/llvm-project?rev=83063&view=rev
Log:
Slightly improve the semantics of extern templates for member functions of class templates

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/SemaTemplate/extern-templates.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=83063&r1=83062&r2=83063&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Sep 29 09:38:03 2009
@@ -977,10 +977,11 @@
                                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)) {

Modified: cfe/trunk/test/SemaTemplate/extern-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/extern-templates.cpp?rev=83063&r1=83062&r2=83063&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/extern-templates.cpp (original)
+++ cfe/trunk/test/SemaTemplate/extern-templates.cpp Tue Sep 29 09:38:03 2009
@@ -39,3 +39,29 @@
 }
 
 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);
+}





More information about the cfe-commits mailing list