From b2a9b2086a4e4b9abe394008ba33017aa71e0a24 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 6 Jun 2005 14:18:22 +0000 Subject: re PR c++/20637 (Confusing message with different using declarations) cp: PR c++/20637 * cp-tree.h (add_method): Add using_decl parameter. * class.c (add_method): Add using_decl parameter. Adjust error messages. (handle_using_decl): Pass the using decl to add_method. (clone_function_decl): Adjust add_member calls. * decl2.c (check_classfn): Likewise. * method.c (lazily_declare_fn): Likewise. * semantics.c (finish_member_declaration): Likewise. * method.c (synthesize_method): Use inform, not warning. testsuite: PR c++/20637 * g++.dg/inherit/using4.C: New. * g++.dg/overload/error1.C: Adjust expected errors. * g++.old-deja/g++.benjamin/warn02.C: Likewise. * g++.old-deja/g++.brendan/arm2.C: Likewise. * g++.old-deja/g++.other/redecl2.C: Likewise. * g++.old-deja/g++.other/redecl4.C: Likewise. * g++.old-deja/g++.pt/memtemp78.C: Likewise. From-SVN: r100664 --- gcc/cp/ChangeLog | 14 ++++++++++++++ gcc/cp/class.c | 50 ++++++++++++++++++++++++++++---------------------- gcc/cp/cp-tree.h | 2 +- gcc/cp/decl2.c | 2 +- gcc/cp/method.c | 6 +++--- gcc/cp/semantics.c | 2 +- 6 files changed, 48 insertions(+), 28 deletions(-) (limited to 'gcc/cp') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d965f8b..758451c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,17 @@ +2005-06-06 Nathan Sidwell + + PR c++/20637 + * cp-tree.h (add_method): Add using_decl parameter. + * class.c (add_method): Add using_decl parameter. Adjust error + messages. + (handle_using_decl): Pass the using decl to add_method. + (clone_function_decl): Adjust add_member calls. + * decl2.c (check_classfn): Likewise. + * method.c (lazily_declare_fn): Likewise. + * semantics.c (finish_member_declaration): Likewise. + + * method.c (synthesize_method): Use inform, not warning. + 2005-06-06 Hans-Peter Nilsson * config-lang.in (target_libs): Remove target-gperf. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index d982b39..8661931 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -878,12 +878,12 @@ modify_vtable_entry (tree t, } -/* Add method METHOD to class TYPE. */ +/* Add method METHOD to class TYPE. If USING_DECL is non-null, it is + the USING_DECL naming METHOD. */ void -add_method (tree type, tree method) +add_method (tree type, tree method, tree using_decl) { - int using; unsigned slot; tree overload; bool template_conv_p = false; @@ -897,7 +897,6 @@ add_method (tree type, tree method) return; complete_p = COMPLETE_TYPE_P (type); - using = (DECL_CONTEXT (method) != type); conv_p = DECL_CONV_FN_P (method); if (conv_p) template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL @@ -1024,21 +1023,28 @@ add_method (tree type, tree method) || same_type_p (TREE_TYPE (TREE_TYPE (fn)), TREE_TYPE (TREE_TYPE (method))))) { - if (using && DECL_CONTEXT (fn) == type) - /* Defer to the local function. */ - return; + if (using_decl) + { + if (DECL_CONTEXT (fn) == type) + /* Defer to the local function. */ + return; + if (DECL_CONTEXT (fn) == DECL_CONTEXT (method)) + cp_error_at ("repeated using declaration %qD", using_decl); + else + cp_error_at ("using declaration %qD conflicts with a previous using declaration", + using_decl); + } else { - cp_error_at ("%q#D and %q#D cannot be overloaded", - method, 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; + cp_error_at ("%q#D cannot be overloaded", method); + cp_error_at ("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; } } } @@ -1201,7 +1207,7 @@ handle_using_decl (tree using_decl, tree t) if (flist) for (; flist; flist = OVL_NEXT (flist)) { - add_method (t, OVL_CURRENT (flist)); + add_method (t, OVL_CURRENT (flist), using_decl); alter_access (t, OVL_CURRENT (flist), access); } else @@ -3829,10 +3835,10 @@ clone_function_decl (tree fn, int update_method_vec_p) and a not-in-charge version. */ clone = build_clone (fn, complete_ctor_identifier); if (update_method_vec_p) - add_method (DECL_CONTEXT (clone), clone); + add_method (DECL_CONTEXT (clone), clone, NULL_TREE); clone = build_clone (fn, base_ctor_identifier); if (update_method_vec_p) - add_method (DECL_CONTEXT (clone), clone); + add_method (DECL_CONTEXT (clone), clone, NULL_TREE); } else { @@ -3851,14 +3857,14 @@ clone_function_decl (tree fn, int update_method_vec_p) { clone = build_clone (fn, deleting_dtor_identifier); if (update_method_vec_p) - add_method (DECL_CONTEXT (clone), clone); + add_method (DECL_CONTEXT (clone), clone, NULL_TREE); } clone = build_clone (fn, complete_dtor_identifier); if (update_method_vec_p) - add_method (DECL_CONTEXT (clone), clone); + add_method (DECL_CONTEXT (clone), clone, NULL_TREE); clone = build_clone (fn, base_dtor_identifier); if (update_method_vec_p) - add_method (DECL_CONTEXT (clone), clone); + add_method (DECL_CONTEXT (clone), clone, NULL_TREE); } /* Note that this is an abstract function that is never emitted. */ diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index bcc6b3f..6cf7fa0 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3667,7 +3667,7 @@ extern tree build_vfn_ref (tree, tree); extern tree get_vtable_decl (tree, int); extern void resort_type_method_vec (void *, void *, gt_pointer_operator, void *); -extern void add_method (tree, tree); +extern void add_method (tree, tree, tree); extern int currently_open_class (tree); extern tree currently_open_derived_class (tree); extern tree finish_struct (tree, tree); diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 48febf7..0501b80 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -709,7 +709,7 @@ check_classfn (tree ctype, tree function, tree template_parms) case we'll only confuse ourselves when the function is declared properly within the class. */ if (COMPLETE_TYPE_P (ctype)) - add_method (ctype, function); + add_method (ctype, function, NULL_TREE); return NULL_TREE; } diff --git a/gcc/cp/method.c b/gcc/cp/method.c index ac85bf4..f5c7d2a 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -806,8 +806,8 @@ synthesize_method (tree fndecl) pop_deferring_access_checks (); if (error_count != errorcount || warning_count != warningcount) - warning (0, "%Hsynthesized method %qD first required here ", - &input_location, fndecl); + inform ("%Hsynthesized method %qD first required here ", + &input_location, fndecl); } /* Use EXTRACTOR to locate the relevant function called for each base & @@ -1119,7 +1119,7 @@ lazily_declare_fn (special_function_kind sfk, tree type) if (sfk == sfk_destructor) check_for_override (fn, type); /* Add it to CLASSTYPE_METHOD_VEC. */ - add_method (type, fn); + add_method (type, fn, NULL_TREE); /* Add it to TYPE_METHODS. */ if (sfk == sfk_destructor && DECL_VIRTUAL_P (fn) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d969a24..76464ad 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2250,7 +2250,7 @@ finish_member_declaration (tree decl) { /* We also need to add this function to the CLASSTYPE_METHOD_VEC. */ - add_method (current_class_type, decl); + add_method (current_class_type, decl, NULL_TREE); TREE_CHAIN (decl) = TYPE_METHODS (current_class_type); TYPE_METHODS (current_class_type) = decl; -- cgit v1.1