From fddabb2c2261f782c6545104c36958b0eef1e3b6 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Tue, 6 Jul 2004 10:51:08 +0000 Subject: [PATCH] re PR c++/3671 (cannot deduce enum template parameter with multiple overloads) 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 | 6 ++++++ gcc/cp/pt.c | 9 ++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/spec14.C | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/spec14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ff63da14f45..f6982704c2e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-07-06 Giovanni Bajo + + PR c++/3671 + * pt.c (convert_nontype_argument): Disallow conversions between + different enumeration types. + 2004-07-06 Nathan Sidwell * cp-tree.h (BINFO_MARKED): Remove. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 9ecec9878de..0a43edead93 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2a29944a62a..4f62f1a2199 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-07-06 Giovanni Bajo + + PR c++/3671 + * g++.dg/template/spec14.C: New test. + 2004-07-05 Jakub Jelinek * 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 index 00000000000..9b59565c465 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/spec14.C @@ -0,0 +1,18 @@ +// { dg-do compile } +// Origin: +// PR c++/3671: Non-type enum parameters must not be converted + +enum T1 {a}; +enum T2 {b}; + +struct Y { + template void foo() {} + template void foo() {} +}; + +struct Z { + template void foo() {} +}; + +template void Y::foo (); +template void Z::foo (); // { dg-error "" } -- 2.30.2