From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id CE98A398C820; Thu, 17 Sep 2020 16:47:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE98A398C820 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600361239; bh=vN6iU+ZfOGVMrmoLBY390wR40LjWhdHT5Wxy6pk/x3s=; h=From:To:Subject:Date:From; b=q4ZIehT6fQnT4nLtxFKXjXPJvPNI1GiLrdUuzdVF+LDXM8AOrtZtui7YuppzxeokB rWcQWmd1PZPH5Ccnmg0J8Rv02TOquQxLHsCzItnNXoY91VVR4XmnOzqa/6g4vSea7y rJ9mjrgbzBMfFmhxe2tLQvnhaBNGVBxq4DUsJ+ag= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/86521 - wrong overload resolution with ref-qualifiers. X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/vendors/redhat/heads/gcc-8-branch X-Git-Oldrev: 59c76c064a74c04266d8365800c0b8e2cc967da9 X-Git-Newrev: 2bcc7a4c0b59cd9ea67409942fb4317c22edff40 Message-Id: <20200917164719.CE98A398C820@sourceware.org> Date: Thu, 17 Sep 2020 16:47:19 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 16:47:19 -0000 https://gcc.gnu.org/g:2bcc7a4c0b59cd9ea67409942fb4317c22edff40 commit 2bcc7a4c0b59cd9ea67409942fb4317c22edff40 Author: Jason Merrill Date: Wed Feb 26 00:33:52 2020 -0500 PR c++/86521 - wrong overload resolution with ref-qualifiers. Here we were wrongly treating binding a const lvalue ref to an xvalue as direct binding, which is wrong under [dcl.init.ref] and [over.match.ref]. gcc/cp/ChangeLog 2020-02-26 Jason Merrill PR c++/86521 - wrong overload resolution with ref-qualifiers. * call.c (build_user_type_conversion_1): Don't use a conversion to a reference of the wrong rvalueness for direct binding. Diff: --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/call.c | 8 ++++++++ gcc/testsuite/g++.dg/cpp0x/overload-conv-3.C | 21 +++++++++++++++++++++ .../testsuite/20_util/is_constructible/value-2.cc | 6 ++++-- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f963baa5122..2b13eba5678 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-02-26 Jason Merrill + + PR c++/86521 - wrong overload resolution with ref-qualifiers. + * call.c (build_user_type_conversion_1): Don't use a conversion to a + reference of the wrong rvalueness for direct binding. + 2020-02-25 Jason Merrill PR c++/89831 - error with qualified-id in const member function. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 0b04eb9629c..dffae0efb5e 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3895,6 +3895,14 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags, cand->reason = arg_conversion_rejection (NULL_TREE, -2, rettype, totype); } + else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p + && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE) + { + /* If we are called to convert to a reference type, we are trying + to find a direct binding per [over.match.ref], so rvaluedness + must match for non-functions. */ + cand->viable = 0; + } else if (DECL_NONCONVERTING_P (cand->fn) && ics->rank > cr_exact) { diff --git a/gcc/testsuite/g++.dg/cpp0x/overload-conv-3.C b/gcc/testsuite/g++.dg/cpp0x/overload-conv-3.C new file mode 100644 index 00000000000..42a135dbf44 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/overload-conv-3.C @@ -0,0 +1,21 @@ +// PR c++/86521 +// { dg-do compile { target c++11 } } + +template T&& move (T&); + +struct Dest { + Dest() = default; + Dest( Dest && ) = default; + Dest( Dest const & ) = delete; +}; + +struct Source { + Dest val; + operator Dest () && { return move( val ); } + operator Dest const & () const & { return val; } +}; + +int main() { + Source x; + Dest d(move(x)); // { dg-error "ambiguous" } +} diff --git a/libstdc++-v3/testsuite/20_util/is_constructible/value-2.cc b/libstdc++-v3/testsuite/20_util/is_constructible/value-2.cc index a2cb9ca5ef6..88644798874 100644 --- a/libstdc++-v3/testsuite/20_util/is_constructible/value-2.cc +++ b/libstdc++-v3/testsuite/20_util/is_constructible/value-2.cc @@ -806,10 +806,12 @@ static_assert(!std::is_constructible>::value, "Error"); // Binding through reference-compatible type is required to perform // direct-initialization as described in [over.match.ref] p. 1 b. 1: static_assert(std::is_constructible>::value, "Error"); -static_assert(std::is_constructible>::value, - "Error"); static_assert(std::is_constructible>::value, "Error"); +// But an xvalue doesn't count for direct binding. +static_assert(!std::is_constructible>::value, + "Error"); + // Binding through temporary behaves like copy-initialization, // see [dcl.init.ref] p. 5, very last sub-bullet: static_assert(!std::is_constructible>::value,