From: Volker Reichelt Date: Wed, 1 Feb 2006 11:52:56 +0000 (+0000) Subject: Backport: X-Git-Tag: releases/gcc-3.4.6~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca540b67b1855193fb4a4d78e6c63999b87ebae3;p=thirdparty%2Fgcc.git Backport: 2005-12-19 Mark Mitchell PR c++/24915 * class.c (add_method): Do not treat templates as identical unless their return types are the same. * g++.dg/template/overload8.C: New test. From-SVN: r110472 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b3b7bf76b564..5ea2f7ddfda8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,4 +1,13 @@ -2006-01-31 Volker Reichelt +2006-02-01 Volker Reichelt + + Backport: + 2005-12-19 Mark Mitchell + + PR c++/24915 + * class.c (add_method): Do not treat templates as identical unless + their return types are the same. + +2006-02-01 Volker Reichelt Backport: 2005-12-19 Mark Mitchell diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 5a0d076a515c..c14313c8bf8b 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -879,9 +879,10 @@ add_method (tree type, tree method, int error_p) fns = OVL_NEXT (fns)) { tree fn = OVL_CURRENT (fns); + tree fn_type; + tree method_type; tree parms1; tree parms2; - bool same = 1; if (TREE_CODE (fn) != TREE_CODE (method)) continue; @@ -896,8 +897,10 @@ add_method (tree type, tree method, int error_p) functions in the derived class override and/or hide member functions with the same name and parameter types in a base class (rather than conflicting). */ - parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn)); - parms2 = TYPE_ARG_TYPES (TREE_TYPE (method)); + fn_type = TREE_TYPE (fn); + method_type = TREE_TYPE (method); + parms1 = TYPE_ARG_TYPES (fn_type); + parms2 = TYPE_ARG_TYPES (method_type); /* Compare the quals on the 'this' parm. Don't compare the whole types, as used functions are treated as @@ -906,23 +909,25 @@ add_method (tree type, tree method, int error_p) && ! DECL_STATIC_FUNCTION_P (method) && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1))) != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2))))) - same = 0; + continue; /* For templates, the template parms must be identical. */ if (TREE_CODE (fn) == TEMPLATE_DECL - && !comp_template_parms (DECL_TEMPLATE_PARMS (fn), - DECL_TEMPLATE_PARMS (method))) - same = 0; + && (!same_type_p (TREE_TYPE (fn_type), + TREE_TYPE (method_type)) + || !comp_template_parms (DECL_TEMPLATE_PARMS (fn), + DECL_TEMPLATE_PARMS (method)))) + continue; if (! DECL_STATIC_FUNCTION_P (fn)) parms1 = TREE_CHAIN (parms1); if (! DECL_STATIC_FUNCTION_P (method)) parms2 = TREE_CHAIN (parms2); - if (same && compparms (parms1, parms2) + if (compparms (parms1, parms2) && (!DECL_CONV_FN_P (fn) - || same_type_p (TREE_TYPE (TREE_TYPE (fn)), - TREE_TYPE (TREE_TYPE (method))))) + || same_type_p (TREE_TYPE (fn_type), + TREE_TYPE (method_type)))) { if (using && DECL_CONTEXT (fn) == type) /* Defer to the local function. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c8b173e85495..4cad37618e17 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,12 @@ -2006-01-31 Volker Reichelt +2006-02-01 Volker Reichelt + + Backport: + 2005-12-19 Mark Mitchell + + PR c++/24915 + * g++.dg/template/overload8.C: New test. + +2006-02-01 Volker Reichelt Backport: 2005-12-19 Mark Mitchell diff --git a/gcc/testsuite/g++.dg/template/overload8.C b/gcc/testsuite/g++.dg/template/overload8.C new file mode 100644 index 000000000000..cc6a05b7041c --- /dev/null +++ b/gcc/testsuite/g++.dg/template/overload8.C @@ -0,0 +1,7 @@ +// PR c++/24915 + +struct A +{ + template void foo() {} + template int foo() {} +};