From 61b493f17e6fea5a0fb45b6a050259ca326c13a7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 9 Jan 2024 05:15:01 -0500 Subject: c++: corresponding object parms [PR113191] As discussed, our handling of corresponding object parameters needed to handle the using-declaration case better. And I took the opportunity to share code between the add_method and cand_parms_match uses. This patch specifically doesn't compare reversed parameters, but a follow-up patch will. PR c++/113191 gcc/cp/ChangeLog: * class.cc (xobj_iobj_parameters_correspond): Add context parm. (object_parms_correspond): Factor out of... (add_method): ...here. * method.cc (defaulted_late_check): Use it. * call.cc (class_of_implicit_object): New. (object_parms_correspond): Overload taking two candidates. (cand_parms_match): Use it. (joust): Check reversed before comparing constraints. * cp-tree.h (object_parms_correspond): Declare. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-memfun4.C: New test. --- gcc/cp/method.cc | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'gcc/cp/method.cc') diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 6a9f03e..d49e5a5 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -3395,24 +3395,18 @@ defaulted_late_check (tree fn) { tree fn_obj_ref_type = TREE_VALUE (fn_parms); /* We can't default xobj operators with an xobj parameter that is not - an lvalue reference. */ + an lvalue reference, even if it would correspond. */ if (!TYPE_REF_P (fn_obj_ref_type) - || TYPE_REF_IS_RVALUE (fn_obj_ref_type)) - return false; - /* If implicit_fn's object parameter is not a pointer, something is not - right. */ - gcc_assert (TYPE_PTR_P (TREE_VALUE (implicit_fn_parms))); - /* Strip the reference/pointer off each object parameter before - comparing them. */ - if (!same_type_p (TREE_TYPE (fn_obj_ref_type), - TREE_TYPE (TREE_VALUE (implicit_fn_parms)))) + || TYPE_REF_IS_RVALUE (fn_obj_ref_type) + || !object_parms_correspond (fn, implicit_fn, + DECL_CONTEXT (implicit_fn))) return false; /* We just compared the object parameters, skip over them before passing to compparms. */ fn_parms = TREE_CHAIN (fn_parms); implicit_fn_parms = TREE_CHAIN (implicit_fn_parms); } - return compparms(fn_parms, implicit_fn_parms); + return compparms (fn_parms, implicit_fn_parms); }; if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)), -- cgit v1.1