Patchwork C++ PATCHes for c++/46105, c++/45102 (bogus partial specialization ambiguities)

login
register
mail settings
Submitter Jason Merrill
Date Sept. 27, 2011, 2:04 a.m.
Message ID <4E812F1C.3080300@redhat.com>
Download mbox | patch
Permalink /patch/116530/
State New
Headers show

Comments

Jason Merrill - Sept. 27, 2011, 2:04 a.m.
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.

Patch

commit 1ef4191889beeb8537cd7adc0f4456b4732435f2
Author: Jason Merrill <jason@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;