This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] PR c++/24915: backport to 3.4 branch
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Tue, 31 Jan 2006 21:21:42 +0100 (CET)
- Subject: [patch] PR c++/24915: backport to 3.4 branch
The following patch is a straightforward backport of Mark's patch
http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01493.html
for PR c++/24915 (rejects-valid bug for templates with different
return types) to the 3.4 branch.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for the 3.4 branch?
Regards,
Volker
:ADDPATCH C++:
2006-01-31 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Backport:
2005-12-19 Mark Mitchell <mark@codesourcery.com>
PR c++/24915
* class.c (add_method): Do not treat templates as identical unless
their return types are the same.
===================================================================
--- gcc/gcc/cp/class.c (revision 110426)
+++ gcc/gcc/cp/class.c (working copy)
@@ -879,9 +879,10 @@
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 @@
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 @@
&& ! 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. */
===================================================================
2006-01-31 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Backport:
2005-12-19 Mark Mitchell <mark@codesourcery.com>
PR c++/24915
* g++.dg/template/overload8.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/overload8.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/overload8.C 2006-01-31 13:01:12 +0100
@@ -0,0 +1,7 @@
+// PR c++/24915
+
+struct A
+{
+ template<int> void foo() {}
+ template<int> int foo() {}
+};
===================================================================