re PR c++/3671 (cannot deduce enum template parameter with multiple overloads)
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>
Tue, 6 Jul 2004 10:51:08 +0000 (10:51 +0000)
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>
Tue, 6 Jul 2004 10:51:08 +0000 (10:51 +0000)
PR c++/3671
* pt.c (convert_nontype_argument): Disallow conversions between
different enumeration types.

PR c++/3671
* g++.dg/template/spec14.C: New test.

From-SVN: r84150

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

index ff63da14f45c6e6f5d83f990ff63b3a175a30480..f6982704c2e60654d4f564039cb0ea87211298aa 100644 (file)
@@ -1,3 +1,9 @@
+2004-07-06  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/3671
+       * pt.c (convert_nontype_argument): Disallow conversions between
+       different enumeration types.
+
 2004-07-06  Nathan Sidwell  <nathan@codesourcery.com>
 
        * cp-tree.h (BINFO_MARKED): Remove.
index 9ecec9878def1eafca795b91eebad5efb51b54b5..0a43edead936008eef603afc99734ac21f134fcc 100644 (file)
@@ -3323,7 +3323,14 @@ convert_nontype_argument (tree type, tree expr)
          conversions (_conv.integral_) are applied.  */
       if (!INTEGRAL_TYPE_P (expr_type))
        return error_mark_node;
-      
+
+      /* [conv.integral] does not allow conversions between two different
+        enumeration types.  */
+      if (TREE_CODE (type) == ENUMERAL_TYPE
+         && TREE_CODE (expr_type) == ENUMERAL_TYPE
+         && !same_type_ignoring_top_level_qualifiers_p (type, expr_type))
+         return error_mark_node;
+
       /* It's safe to call digest_init in this case; we know we're
         just converting one integral constant expression to another.  */
       expr = digest_init (type, expr, (tree*) 0);
index 2a29944a62a8f2f2708078f10fe77556f4114472..4f62f1a2199bd799c6710dfa997855a1a58adfd2 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-06  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/3671
+       * g++.dg/template/spec14.C: New test.
+
 2004-07-05  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/execute/20040629-1.c (FIELDS1, FIELDS2): Define to
diff --git a/gcc/testsuite/g++.dg/template/spec14.C b/gcc/testsuite/g++.dg/template/spec14.C
new file mode 100644 (file)
index 0000000..9b59565
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// Origin: <weissr at informatik dot uni-tuebingen dot de>
+// PR c++/3671: Non-type enum parameters must not be converted
+
+enum T1 {a};
+enum T2 {b};
+
+struct Y {
+  template <T1 i> void foo() {}
+  template <T2 i> void foo() {}
+};
+
+struct Z {
+  template <T1 i> void foo() {}
+};
+
+template void Y::foo<b> ();
+template void Z::foo<b> ();   // { dg-error "" }