The code for recognizing a constrained partial specialization of a class was incorrectly treating the template friend as a partial specialization because "class A" was finding the injected-class-name from the enclosing scope.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 1155b92a5e8151ba85a35661089972658074607b
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Dec 7 10:02:29 2015 -0500

    	PR c++/68170
    	* pt.c (maybe_new_partial_specialization): The injected-class-name
    	is not a new partial specialization.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 22dcee2..60cc94c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -855,6 +855,10 @@ maybe_new_partial_specialization (tree type)
       if (!current_template_parms)
         return NULL_TREE;
 
+      // The injected-class-name is not a new partial specialization.
+      if (DECL_SELF_REFERENCE_P (TYPE_NAME (type)))
+	return NULL_TREE;
+
       // If the constraints are not the same as those of the primary
       // then, we can probably create a new specialization.
       tree type_constr = current_template_constraints ();
diff --git a/gcc/testsuite/g++.dg/template/friend60.C b/gcc/testsuite/g++.dg/template/friend60.C
new file mode 100644
index 0000000..5ba9ab2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend60.C
@@ -0,0 +1,13 @@
+// PR c++/68170
+
+template< typename T >
+class A
+{
+};
+
+template<>
+class A< void >
+{
+  template< typename X >
+  friend class A;
+};

Reply via email to