While discussing issue 2179 at the meeting last week, I noticed that we were crashing when a partial specialization made a previous instantiation ambiguous. Fixed thus.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit cb0817f19d7f4ce9878922412c2c1b2d07eb66d7
Author: Jason Merrill <ja...@redhat.com>
Date:   Sun Oct 25 05:22:50 2015 -1000

    	DR 2179
    	* pt.c (process_partial_specialization): Handle error_mark_node
    	from most_specialized_partial_spec.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ffe02da..2745b40 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4690,14 +4690,18 @@ process_partial_specialization (tree decl)
 	  : DECL_TEMPLATE_INSTANTIATION (instance))
 	{
 	  tree spec = most_specialized_partial_spec (instance, tf_none);
-	  if (spec && TREE_VALUE (spec) == tmpl)
-	    {
-	      tree inst_decl = (DECL_P (instance)
-				? instance : TYPE_NAME (instance));
-	      permerror (input_location,
-			 "partial specialization of %qD after instantiation "
-			 "of %qD", decl, inst_decl);
-	    }
+	  tree inst_decl = (DECL_P (instance)
+			    ? instance : TYPE_NAME (instance));
+	  if (!spec)
+	    /* OK */;
+	  else if (spec == error_mark_node)
+	    permerror (input_location,
+		       "declaration of %qD ambiguates earlier template "
+		       "instantiation for %qD", decl, inst_decl);
+	  else if (TREE_VALUE (spec) == tmpl)
+	    permerror (input_location,
+		       "partial specialization of %qD after instantiation "
+		       "of %qD", decl, inst_decl);
 	}
     }
 
diff --git a/gcc/testsuite/g++.dg/template/partial-specialization3.C b/gcc/testsuite/g++.dg/template/partial-specialization3.C
new file mode 100644
index 0000000..c5f83bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/partial-specialization3.C
@@ -0,0 +1,7 @@
+// DR 2179
+
+template <class T1, class T2> class A;
+template <class T> struct A<T, void> { void f(); };
+template <class T> void g(T) { A<char, void>().f(); }   // #1
+template<typename T> struct A<char, T> {};		// { dg-error "" }
+A<char, void> f;   // #2

Reply via email to