This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
(C++) patch to catch invalid overloads
- To: egcs-patches at cygnus dot com
- Subject: (C++) patch to catch invalid overloads
- From: Jason Merrill <jason at cygnus dot com>
- Date: Tue, 24 Nov 1998 17:55:33 -0800
1998-11-24 Jason Merrill <jason@yorick.cygnus.com>
* class.c (add_method): Catch invalid overloads.
Index: class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.114
diff -c -p -r1.114 class.c
*** class.c 1998/11/24 02:33:46 1.114
--- class.c 1998/11/25 01:53:24
*************** add_method (type, fields, method)
*** 1208,1213 ****
--- 1208,1233 ----
if (TREE_CODE (method) != TEMPLATE_DECL)
{
+ /* [over.load] Member function declarations with the
+ same name and the same parameter types cannot be
+ overloaded if any of them is a static member
+ function declaration. */
+ if (DECL_STATIC_FUNCTION_P (fn)
+ != DECL_STATIC_FUNCTION_P (method))
+ {
+ tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
+ tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
+
+ if (! DECL_STATIC_FUNCTION_P (fn))
+ parms1 = TREE_CHAIN (parms1);
+ else
+ parms2 = TREE_CHAIN (parms2);
+
+ if (compparms (parms1, parms2))
+ cp_error ("`%#D' and `%#D' cannot be overloaded",
+ fn, method);
+ }
+
/* Since this is an ordinary function in a
non-template class, it's mangled name can be
used as a unique identifier. This technique