From 5a6d3b1737843aa64d83ffc5d639fa0afa5d8318 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 9 Jan 2024 16:00:52 -0500 Subject: [PATCH 1/2] c++: explicit object cleanups To: gcc-patches@gcc.gnu.org The FIXME in xobj_iobj_parameters_correspond was due to expecting TYPE_MAIN_VARIANT to be the same for all equivalent types, which is not the case. And I adjusted some comments that I disagree with; the iobj parameter adjustment only applies to overload resolution, we can handle that in cand_parms_match (and I have WIP for that). gcc/cp/ChangeLog: * call.cc (build_over_call): Refactor handle_arg lambda. * class.cc (xobj_iobj_parameters_correspond): Fix FIXME. * method.cc (defaulted_late_check): Adjust comments. --- gcc/cp/call.cc | 24 ++++++++++++------------ gcc/cp/class.cc | 40 ++++++++++++---------------------------- gcc/cp/method.cc | 7 +------ 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index dca8e5090e2..7d3d67600c8 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -10187,11 +10187,11 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) parm = TREE_CHAIN (parm); } - auto handle_arg = [fn, flags, complain](tree type, - tree arg, - int const param_index, - conversion *conv, - bool const conversion_warning) + auto handle_arg = [fn, flags](tree type, + tree arg, + int const param_index, + conversion *conv, + tsubst_flags_t const arg_complain) { /* Set user_conv_p on the argument conversions, so rvalue/base handling knows not to allow any more UDCs. This needs to happen after we @@ -10199,9 +10199,6 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (flags & LOOKUP_NO_CONVERSION) conv->user_conv_p = true; - tsubst_flags_t const arg_complain - = conversion_warning ? complain : complain & ~tf_warning; - if (arg_complain & tf_warning) maybe_warn_pessimizing_move (arg, type, /*return_p=*/false); @@ -10214,13 +10211,12 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (DECL_XOBJ_MEMBER_FUNCTION_P (fn)) { gcc_assert (cand->num_convs > 0); - static constexpr bool conversion_warning = true; tree object_arg = consume_object_arg (); val = handle_arg (TREE_VALUE (parm), object_arg, param_index++, convs[conv_index++], - conversion_warning); + complain); if (val == error_mark_node) return error_mark_node; @@ -10260,11 +10256,14 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) && cand->template_decl && !cand->explicit_targs); + tsubst_flags_t const arg_complain + = conversion_warning ? complain : complain & ~tf_warning; + val = handle_arg (TREE_VALUE (parm), current_arg, param_index, convs[conv_index], - conversion_warning); + arg_complain); if (val == error_mark_node) return error_mark_node; @@ -10273,7 +10272,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) } /* Default arguments */ - for (; parm && parm != void_list_node; parm = TREE_CHAIN (parm), param_index++) + for (; parm && parm != void_list_node; + parm = TREE_CHAIN (parm), param_index++) { if (TREE_VALUE (parm) == error_mark_node) return error_mark_node; diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index f3cfa9f0f23..e5e609badf3 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -1020,9 +1020,12 @@ modify_vtable_entry (tree t, /* Check if the object parameters of an xobj and iobj member function - correspond. This function assumes that the iobj parameter has been correctly - adjusted when the function is introduced by a using declaration per - [over.match.funcs.general.4]. */ + correspond. This function assumes that the iobj parameter has been + correctly adjusted when the function is introduced by a using declaration + per [over.match.funcs.general.4]. + + ??? But it isn't, that's only considered at overload resolution time. + cand_parms_match will probably need to check cand->conversion_path. */ bool xobj_iobj_parameters_correspond (tree fn1, tree fn2) @@ -1112,29 +1115,10 @@ xobj_iobj_parameters_correspond (tree fn1, tree fn2) handles xobj parameters of pointer type, we don't have to explicitly check for that case. */ - /* FIXME: - - template - struct S; - - template - struct B { - int f(this S&) requires true { return 5; } - }; - - template - struct S : B { - using B::f; - int f() { return 10; } - }; - - This case is broken, the incomplete type seems to screw with things. - I'm not sure how to fix that so I'm just noting the issue here, I have a - feeling it's trivial to do if you know how. */ - - if (TYPE_MAIN_VARIANT (iobj_param_type) - != TYPE_MAIN_VARIANT (non_reference (xobj_param))) + if (!same_type_ignoring_top_level_qualifiers_p + (iobj_param_type, non_reference (xobj_param))) return false; + /* We don't get to bail yet even if we have a by-value xobj parameter, a by-value xobj parameter can correspond to an iobj parameter provided the iobj member function is not declared with a reference qualifier. @@ -8976,9 +8960,9 @@ resolve_address_of_overloaded_function (tree target_type, documentation for -fms-extensions states it's purpose is to support the use of microsoft headers. Until otherwise demonstrated, we should assume xobj member functions are not used in this manner in microsoft - headers and indiscriminately forbid the incorrect syntax instead of - supporting it for non-legacy uses. This should hopefully encourage - conformance going forward. + headers and forbid the incorrect syntax instead of supporting it for + non-legacy uses. This should hopefully encourage conformance going + forward. This comment is referred to in typeck.cc:cp_build_addr_expr_1. */ if (DECL_IOBJ_MEMBER_FUNCTION_P (fn) && flag_ms_extensions) /* Early escape. */; diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index da6a08a0304..6a9f03eb8f3 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -3400,8 +3400,7 @@ defaulted_late_check (tree fn) || TYPE_REF_IS_RVALUE (fn_obj_ref_type)) return false; /* If implicit_fn's object parameter is not a pointer, something is not - right. (Or we have finally changed the type of the iobj parameter - in iobj member functions.) */ + right. */ gcc_assert (TYPE_PTR_P (TREE_VALUE (implicit_fn_parms))); /* Strip the reference/pointer off each object parameter before comparing them. */ @@ -3422,10 +3421,6 @@ defaulted_late_check (tree fn) { error ("defaulted declaration %q+D does not match the " "expected signature", fn); - /* FIXME: If the user is defaulting an xobj member function we should - emit an xobj member function for a signature. When we do this, maybe - we can just synthesize implicit_fn as an xobj member function and - avoid the dance in compare_fn_parms. */ inform (DECL_SOURCE_LOCATION (fn), "expected signature: %qD", implicit_fn); } -- 2.39.3