diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-11 22:34:58 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-11 22:34:58 +0000 |
commit | 198559b77dae59b9338684dadbd41bc14948381e (patch) | |
tree | 90f277ecbe5b38cb2556b27b25b668755cb1360e | |
parent | 302d62c3218278a60d6b755f5ea3077908c1e916 (diff) | |
download | ppe42-gcc-198559b77dae59b9338684dadbd41bc14948381e.tar.gz ppe42-gcc-198559b77dae59b9338684dadbd41bc14948381e.zip |
PR c++/7224
* class.c (add_method): Simplify.
PR c++/7224
* g++.dg/overload/error1.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55409 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/class.c | 100 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/overload/error1.C | 7 |
4 files changed, 61 insertions, 56 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 24b9267a196..38de1a298e5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2002-07-11 Mark Mitchell <mark@codesourcery.com> + + PR c++/7224 + * class.c (add_method): Simplify. + 2002-07-11 Jason Merrill <jason@redhat.com> PR c++/7279 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index f2544bd1f52..5222665f7bd 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -966,69 +966,57 @@ add_method (type, method, error_p) fns = OVL_NEXT (fns)) { tree fn = OVL_CURRENT (fns); - + tree parms1; + tree parms2; + bool same = 1; + if (TREE_CODE (fn) != TREE_CODE (method)) continue; - 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. + + [namespace.udecl] When a using-declaration brings names + from a base class into a derived class scope, member + 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)); + + /* Compare the quals on the 'this' parm. Don't compare + the whole types, as used functions are treated as + coming from the using class in overload resolution. */ + if (! DECL_STATIC_FUNCTION_P (fn) + && ! DECL_STATIC_FUNCTION_P (method) + && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1))) + != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2))))) + same = 0; + 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)) { - /* [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. - - [namespace.udecl] When a using-declaration brings names - from a base class into a derived class scope, member - 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). */ - if ((DECL_STATIC_FUNCTION_P (fn) - != DECL_STATIC_FUNCTION_P (method)) - || using) + if (using && DECL_CONTEXT (fn) == type) + /* Defer to the local function. */ + return; + else { - tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn)); - tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method)); - int same = 1; - - /* Compare the quals on the 'this' parm. Don't compare - the whole types, as used functions are treated as - coming from the using class in overload resolution. */ - if (using - && ! DECL_STATIC_FUNCTION_P (fn) - && ! DECL_STATIC_FUNCTION_P (method) - && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1))) - != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2))))) - same = 0; - 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 (using && DECL_CONTEXT (fn) == type) - /* Defer to the local function. */ - return; - else - error ("`%#D' and `%#D' cannot be overloaded", - fn, method); - } + cp_error_at ("`%#D' and `%#D' cannot be overloaded", + method, fn, method); + + /* We don't call duplicate_decls here to merge + the declarations because that will confuse + things if the methods have inline + definitions. In particular, we will crash + while processing the definitions. */ + return; } } - - if (!decls_match (fn, method)) - continue; - - /* There has already been a declaration of this method - or member template. */ - cp_error_at ("`%D' has already been declared in `%T'", - method, type); - - /* We don't call duplicate_decls here to merge the - declarations because that will confuse things if the - methods have inline definitions. In particular, we - will crash while processing the definitions. */ - return; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 734987b8f2f..13605c9e619 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-07-11 Mark Mitchell <mark@codesourcery.com> + + PR c++/7224 + * g++.dg/overload/error1.C: New test. + 2002-07-11 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE> * gcc.misc-tests/linkage.exp: Handle mips-sgi-irix6*o32 diff --git a/gcc/testsuite/g++.dg/overload/error1.C b/gcc/testsuite/g++.dg/overload/error1.C new file mode 100644 index 00000000000..fcaa445201e --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/error1.C @@ -0,0 +1,7 @@ +// { dg-do compile } + +struct S +{ + void f () {} + int f () { return 0; } // { dg-error "" "" } +}; |