Skip to content

Commit

Permalink
c++: explicit object cleanups
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jicama authored and Liaoshihua committed Mar 13, 2024
1 parent 52976a5 commit 283f10d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 46 deletions.
24 changes: 12 additions & 12 deletions gcc/cp/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10187,21 +10187,18 @@ 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
process cand->warnings. */
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);

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
40 changes: 12 additions & 28 deletions gcc/cp/class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<typename>
struct S;
template<typename>
struct B {
int f(this S<void>&) requires true { return 5; }
};
template<typename>
struct S : B<void> {
using B<void>::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.
Expand Down Expand Up @@ -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. */;
Expand Down
7 changes: 1 addition & 6 deletions gcc/cp/method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
}
Expand Down

0 comments on commit 283f10d

Please sign in to comment.