diff options
author | lmillward <lmillward@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-06 01:06:04 +0000 |
---|---|---|
committer | lmillward <lmillward@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-06 01:06:04 +0000 |
commit | 1965e597d485a9dae4f903f4ec56803a37dc659d (patch) | |
tree | 31f90be90aa6483c30ebb38a4dce943b957bb1c8 /gcc/cp | |
parent | a9a6a36ac96b3ba62f6e9b600e3f5ae6a792b930 (diff) | |
download | gcc-1965e597d485a9dae4f903f4ec56803a37dc659d.tar.gz |
PR c++/19439
* class.c (add_method): Don't wait until template
instantiation time to complain about duplicate methods.
* g++.dg/template/duplicate1.C: New test
* g++.dg/template/memfriend6.C: Adjust error markers.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120520 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/class.c | 149 |
2 files changed, 77 insertions, 78 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3c35e5825bf..fc2637fc274 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-01-06 Lee Millward <lee.millward@codesourcery.com> + + PR c++/19439 + * class.c (add_method): Don't wait until template + instantiation time to complain about duplicate methods. + 2007-01-05 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR c/19978 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 6b195fb1f25..b56ef8476de 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1,6 +1,7 @@ /* Functions related to building classes and their related objects. Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 + Free Software Foundation, Inc. Contributed by Michael Tiemann (tiemann@cygnus.com) This file is part of GCC. @@ -898,6 +899,7 @@ add_method (tree type, tree method, tree using_decl) bool complete_p; bool insert_p = false; tree current_fns; + tree fns; if (method == error_mark_node) return false; @@ -975,92 +977,83 @@ add_method (tree type, tree method, tree using_decl) } current_fns = insert_p ? NULL_TREE : VEC_index (tree, method_vec, slot); - if (processing_template_decl) - /* TYPE is a template class. Don't issue any errors now; wait - until instantiation time to complain. */ - ; - else + /* Check to see if we've already got this method. */ + for (fns = current_fns; fns; fns = OVL_NEXT (fns)) { - tree fns; - - /* Check to see if we've already got this method. */ - for (fns = current_fns; fns; fns = OVL_NEXT (fns)) - { - tree fn = OVL_CURRENT (fns); - tree fn_type; - tree method_type; - tree parms1; - tree parms2; + tree fn = OVL_CURRENT (fns); + tree fn_type; + tree method_type; + tree parms1; + tree parms2; - if (TREE_CODE (fn) != TREE_CODE (method)) - continue; + if (TREE_CODE (fn) != TREE_CODE (method)) + continue; - /* [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). */ - 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 - 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))))) - continue; + /* [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). */ + 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 + 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))))) + continue; - /* For templates, the return type and template parameters - must be identical. */ - if (TREE_CODE (fn) == TEMPLATE_DECL - && (!same_type_p (TREE_TYPE (fn_type), - TREE_TYPE (method_type)) - || !comp_template_parms (DECL_TEMPLATE_PARMS (fn), - DECL_TEMPLATE_PARMS (method)))) - continue; + /* For templates, the return type and template parameters + must be identical. */ + if (TREE_CODE (fn) == TEMPLATE_DECL + && (!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 (! DECL_STATIC_FUNCTION_P (fn)) + parms1 = TREE_CHAIN (parms1); + if (! DECL_STATIC_FUNCTION_P (method)) + parms2 = TREE_CHAIN (parms2); - if (compparms (parms1, parms2) - && (!DECL_CONV_FN_P (fn) - || same_type_p (TREE_TYPE (fn_type), - TREE_TYPE (method_type)))) + if (compparms (parms1, parms2) + && (!DECL_CONV_FN_P (fn) + || same_type_p (TREE_TYPE (fn_type), + TREE_TYPE (method_type)))) + { + if (using_decl) { - if (using_decl) - { - if (DECL_CONTEXT (fn) == type) - /* Defer to the local function. */ - return false; - if (DECL_CONTEXT (fn) == DECL_CONTEXT (method)) - error ("repeated using declaration %q+D", using_decl); - else - error ("using declaration %q+D conflicts with a previous using declaration", - using_decl); - } + if (DECL_CONTEXT (fn) == type) + /* Defer to the local function. */ + return false; + if (DECL_CONTEXT (fn) == DECL_CONTEXT (method)) + error ("repeated using declaration %q+D", using_decl); else - { - error ("%q+#D cannot be overloaded", method); - error ("with %q+#D", fn); - } - - /* 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 false; + error ("using declaration %q+D conflicts with a previous using declaration", + using_decl); + } + else + { + error ("%q+#D cannot be overloaded", method); + error ("with %q+#D", fn); } + + /* 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 false; } } |