OSDN Git Service

PR c++/42466
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 22 Dec 2009 23:16:46 +0000 (23:16 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 22 Dec 2009 23:16:46 +0000 (23:16 +0000)
* pt.c (reduce_template_parm_level): Check the type before
returning cached TEMPLATE_PARM_INDEX.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155411 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/nontype19.C [new file with mode: 0644]

index b75e38a..65d40e2 100644 (file)
@@ -1,5 +1,9 @@
 2009-12-22  Jason Merrill  <jason@redhat.com>
 
+       PR c++/42466
+       * pt.c (reduce_template_parm_level): Check the type before
+       returning cached TEMPLATE_PARM_INDEX.
+
        PR c++/42331
        * typeck.c (cp_build_modify_expr): Fix thinko.
 
index bb7c167..85ad539 100644 (file)
@@ -3356,7 +3356,8 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args,
 {
   if (TEMPLATE_PARM_DESCENDANTS (index) == NULL_TREE
       || (TEMPLATE_PARM_LEVEL (TEMPLATE_PARM_DESCENDANTS (index))
-         != TEMPLATE_PARM_LEVEL (index) - levels))
+         != TEMPLATE_PARM_LEVEL (index) - levels)
+      || !same_type_p (type, TREE_TYPE (TEMPLATE_PARM_DESCENDANTS (index))))
     {
       tree orig_decl = TEMPLATE_PARM_DECL (index);
       tree decl, t;
index cfd4b5e..59d3a09 100644 (file)
@@ -1,5 +1,8 @@
 2009-12-22  Jason Merrill  <jason@redhat.com>
 
+       PR c++/42466
+       * g++.dg/template/nontype19.C: New.
+
        PR c++/42331
        * g++.dg/cpp0x/initlist29.C: New.
 
diff --git a/gcc/testsuite/g++.dg/template/nontype19.C b/gcc/testsuite/g++.dg/template/nontype19.C
new file mode 100644 (file)
index 0000000..1df78b3
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/42466
+
+template<class IntT, IntT X>
+struct A
+{
+  A();
+
+  template<IntT X2>
+  A(const A<IntT, X2>& other);
+};
+
+int main(int argc, char** argv)
+{
+    A<int, 42> a;
+    A<int, 100> b = a;
+
+    A<unsigned, 42u> c;
+    A<unsigned, 100u> d = c;
+}