From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id BAF1E3858D39; Fri, 26 Jan 2024 14:42:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAF1E3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706280140; bh=n4aKFSvqjGLlZ8fOWEFhKzMLVaEzKTrUZMbJf8zJqfw=; h=From:To:Subject:Date:From; b=yGtXcliXBizsigIoN9F+D/tI0gNWXYRqFxlZ4knTeYtOuMAQCWSK+dKZ8R9rBUrgo g97k0QOkb4IRdU6oRDWYlwIM3yyxSamumovVtb/kTgSdLPHzbM9jzhySpb3o7Fe3qJ gRSqysWnFFZ3pkOnavJ9+fkjSFtU/0lgwh0Xtw3c= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8255] c++: ambiguous member lookup for rewritten cands [PR113529] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 85411f8d854580c065aeed9b9cb41033764352bf X-Git-Newrev: 663d9e168bc1f2649721436f5188563eda9d04f0 Message-Id: <20240126144220.BAF1E3858D39@sourceware.org> Date: Fri, 26 Jan 2024 14:42:20 +0000 (GMT) List-Id: https://gcc.gnu.org/g:663d9e168bc1f2649721436f5188563eda9d04f0 commit r13-8255-g663d9e168bc1f2649721436f5188563eda9d04f0 Author: Patrick Palka Date: Wed Jan 24 17:11:09 2024 -0500 c++: ambiguous member lookup for rewritten cands [PR113529] Here we handle the operator expression u < v inconsistently: in a SFINAE context we accept it, and in a non-SFINAE context we reject it with error: request for member 'operator<=>' is ambiguous as per [class.member.lookup]/6. This inconsistency is ultimately because we neglect to propagate error_mark_node after recursing in add_operator_candidates, fixed like so. PR c++/113529 gcc/cp/ChangeLog: * call.cc (add_operator_candidates): Propagate error_mark_node result after recursing to find rewritten candidates. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-sfinae3.C: New test. Reviewed-by: Jason Merrill (cherry picked from commit fecb45a936d62ca24dd8b4985ea0555c28edefa8) Diff: --- gcc/cp/call.cc | 21 +++++++++++++++------ gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae3.C | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 85274b81d7e2..d012680f1857 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -6731,7 +6731,9 @@ op_is_ordered (tree_code code) /* Subroutine of build_new_op: Add to CANDIDATES all candidates for the operator indicated by CODE/CODE2. This function calls itself recursively to - handle C++20 rewritten comparison operator candidates. + handle C++20 rewritten comparison operator candidates. Returns NULL_TREE + upon success, and error_mark_node if something went wrong that prevented + us from performing overload resolution (e.g. ambiguous member name lookup). LOOKUPS, if non-NULL, is the set of pertinent namespace-scope operator overloads to consider. This parameter is used when instantiating a @@ -6908,11 +6910,16 @@ add_operator_candidates (z_candidate **candidates, if (rewrite_code) { + tree r; flags |= LOOKUP_REWRITTEN; if (rewrite_code != code) - /* Add rewritten candidates in same order. */ - add_operator_candidates (candidates, rewrite_code, ERROR_MARK, - arglist, lookups, flags, complain); + { + /* Add rewritten candidates in same order. */ + r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK, + arglist, lookups, flags, complain); + if (r == error_mark_node) + return error_mark_node; + } z_candidate *save_cand = *candidates; @@ -6921,8 +6928,10 @@ add_operator_candidates (z_candidate **candidates, vec *revlist = make_tree_vector (); revlist->quick_push ((*arglist)[1]); revlist->quick_push ((*arglist)[0]); - add_operator_candidates (candidates, rewrite_code, ERROR_MARK, - revlist, lookups, flags, complain); + r = add_operator_candidates (candidates, rewrite_code, ERROR_MARK, + revlist, lookups, flags, complain); + if (r == error_mark_node) + return error_mark_node; /* Release the vec if we didn't add a candidate that uses it. */ for (z_candidate *c = *candidates; c != save_cand; c = c->next) diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae3.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae3.C new file mode 100644 index 000000000000..ca159260ec79 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae3.C @@ -0,0 +1,22 @@ +// PR c++/113529 +// { dg-do compile { target c++20 } } + +#include + +struct A { + auto operator<=>(const A&) const = default; + bool operator<(const A&) const; +}; +struct B { + auto operator<=>(const B&) const = default; +}; +struct C : A, B { }; + + +template +void f(T u, T v) { + static_assert(!requires { u < v; }); + u < v; // { dg-error "request for member 'operator<=>' is ambiguous" } +} + +template void f(C, C);