When Paolo asked earlier, I thought these two were the same bug, but on investigation they turned out to be unrelated. In 46105 we were treating (const T)::element_type as different from T::element_type, and in 45102 we were pulling out the constant value of RUNTIME and then deciding it was different from RUNTIME itself.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0db4d89b8edbade4ccfa71294a53528804f2b675
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Sep 26 18:15:38 2011 -0400

    	PR c++/46105
    	* typeck.c (structural_comptypes): Ignore cv-quals on typename scope.

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 955e37a..10f17bf 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1300,7 +1300,9 @@ structural_comptypes (tree t1, tree t2, int strict)
       if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
 			  TYPENAME_TYPE_FULLNAME (t2)))
 	return false;
-      if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
+      /* Qualifiers don't matter on scopes.  */
+      if (!same_type_ignoring_top_level_qualifiers_p (TYPE_CONTEXT (t1),
+						      TYPE_CONTEXT (t2)))
 	return false;
       break;
 
diff --git a/gcc/testsuite/g++.dg/template/partial12.C b/gcc/testsuite/g++.dg/template/partial12.C
new file mode 100644
index 0000000..05a3eca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/partial12.C
@@ -0,0 +1,27 @@
+// PR c++/46105
+
+template< typename T >
+struct empty { // support class is like stripped-down enable_if
+    typedef void type;
+};
+
+template< class T, typename v = void > // v is always void!
+struct element {
+    typedef typename T::value_type type;
+};
+
+template< class T > // T in deduced context, T::element_type is SFINAE:
+struct element< T, typename empty< typename T::element_type >::type > {
+    typedef typename T::element_type type;
+};
+
+template< class T >
+struct element< T const, typename empty< typename T::element_type >::type > {
+    typedef typename T::element_type const type;
+};
+
+struct has_et {
+    typedef int element_type;
+};
+
+element<has_et const>::type ip = 0;
commit 1ef4191889beeb8537cd7adc0f4456b4732435f2
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Sep 26 18:53:20 2011 -0400

    	PR c++/45102
    	* pt.c (tsubst_copy_and_build) [CONST_DECL]: Don't pull out
    	constant value if we're still in a template.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index cac45f9..4d57f94 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13916,7 +13916,7 @@ tsubst_copy_and_build (tree t,
       t = tsubst_copy (t, args, complain, in_decl);
       /* As in finish_id_expression, we resolve enumeration constants
 	 to their underlying values.  */
-      if (TREE_CODE (t) == CONST_DECL)
+      if (TREE_CODE (t) == CONST_DECL && !processing_template_decl)
 	{
 	  used_types_insert (TREE_TYPE (t));
 	  return DECL_INITIAL (t);
diff --git a/gcc/testsuite/g++.dg/template/partial13.C b/gcc/testsuite/g++.dg/template/partial13.C
new file mode 100644
index 0000000..bfbe2e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/partial13.C
@@ -0,0 +1,25 @@
+// PR c++/45012
+
+template <bool B, class T=void> struct enable_if;
+
+template <class T>
+struct enable_if<true,T>
+{
+  typedef T type;
+};
+
+enum { RUNTIME = 0 };
+// it compiles with the previous line commented out and the next commented in
+// static const int RUNTIME=0;
+
+template <class T, class U, class EN=void> struct foo;
+
+template <template<int> class V, int M>
+struct foo<V<M>,V<M>, typename enable_if<M==RUNTIME||M==2>::type> {};
+
+template <template<int> class V1, template<int> class V2, int M>
+struct foo<V1<M>,V2<M>, typename enable_if<M==RUNTIME||M==2>::type> {};
+
+template <int M> struct bar {};
+
+foo<bar<2>,bar<2> > x;

Reply via email to