Patchwork C++ PATCH for c++/45651 (ICE with explicit template instantiation and unnamed namespace)

login
register
mail settings
Submitter Jason Merrill
Date March 8, 2011, 5:23 p.m.
Message ID <4D766617.10105@redhat.com>
Download mbox | patch
Permalink /patch/86025/
State New
Headers show

Comments

Jason Merrill - March 8, 2011, 5:23 p.m.
The linkage handling of an explicit instantiation of an undefined 
template in instantiate_decl was interacting badly with the linkage 
magic for anonymous namespaces.  Fixed thus.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit bb206a6c192120614fa6e3c78a2ba2add6f5c3f2
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Mar 8 10:54:00 2011 -0500

    	PR c++/45651
    	* pt.c (instantiate_decl): Don't clear DECL_INTERFACE_KNOWN on
    	!TREE_PUBLIC decls.

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 076224c..48f9382 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17224,8 +17224,13 @@  instantiate_decl (tree d, int defer_ok,
   if (!pattern_defined && expl_inst_class_mem_p
       && DECL_EXPLICIT_INSTANTIATION (d))
     {
-      DECL_NOT_REALLY_EXTERN (d) = 0;
-      DECL_INTERFACE_KNOWN (d) = 0;
+      /* Leave linkage flags alone on instantiations with anonymous
+	 visibility.  */
+      if (TREE_PUBLIC (d))
+	{
+	  DECL_NOT_REALLY_EXTERN (d) = 0;
+	  DECL_INTERFACE_KNOWN (d) = 0;
+	}
       SET_DECL_IMPLICIT_INSTANTIATION (d);
     }
 
diff --git a/gcc/testsuite/g++.dg/template/anon5.C b/gcc/testsuite/g++.dg/template/anon5.C
new file mode 100644
index 0000000..34599c0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/anon5.C
@@ -0,0 +1,6 @@ 
+// PR c++/45651
+
+namespace { template <int T> struct A {}; }
+template <int T> struct B { void f(A<T>); };
+template struct B<1>;
+template<int T> void B<T>::f(A<T>) {}