From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 6CFA13858CDB; Thu, 30 Mar 2023 08:08:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CFA13858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680163715; bh=10KQnpnqM2nL1MM9m0LRCPdEZE7x5dBVCuDVU4wxJSw=; h=From:To:Subject:Date:From; b=n5csNHGnOnHHk3EUuMVKOP0QQp5qn/EXIplnGZRV8twSQI5i6H5CICPE9maRbDC7D 0t5kQmS8+amFz9jGavKCtfVbLWx31z9jqxrwSCN1+nhSW6At2tgfaw7sSFo/ovYRsM gNJSl++qAqNPyaIeyF4LZ15/9RQNQrsJoTGz8B/E= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-9369] libstdc++: Use std::remove_cv_t in std::optional::transform [PR109242] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 2fddea0fd2822135129118282d5814bc7880de57 X-Git-Newrev: 82e8d1685a1e5fac4880e987ed9684248378bce2 Message-Id: <20230330080835.6CFA13858CDB@sourceware.org> Date: Thu, 30 Mar 2023 08:08:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:82e8d1685a1e5fac4880e987ed9684248378bce2 commit r12-9369-g82e8d1685a1e5fac4880e987ed9684248378bce2 Author: Jonathan Wakely Date: Wed Mar 29 22:16:55 2023 +0100 libstdc++: Use std::remove_cv_t in std::optional::transform [PR109242] We need to strip cv-qualifiers from the result of the callable passed to std::optional::transform. libstdc++-v3/ChangeLog: PR libstdc++/109242 * include/std/optional (transform): Use std::remove_cv_t. * testsuite/20_util/optional/monadic/pr109242.cc: New test. (cherry picked from commit 31a909712014b75fc6ae2ca5eaa425f218bb5f32) Diff: --- libstdc++-v3/include/std/optional | 8 ++--- .../testsuite/20_util/optional/monadic/pr109242.cc | 35 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional index 791ef6f1994..122ff7e5863 100644 --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -1100,7 +1100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr auto transform(_Fn&& __f) & { - using _Up = invoke_result_t<_Fn, _Tp&>; + using _Up = remove_cv_t>; if (has_value()) return optional<_Up>(_Optional_func<_Fn>{__f}, **this); else @@ -1111,7 +1111,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr auto transform(_Fn&& __f) const & { - using _Up = invoke_result_t<_Fn, const _Tp&>; + using _Up = remove_cv_t>; if (has_value()) return optional<_Up>(_Optional_func<_Fn>{__f}, **this); else @@ -1122,7 +1122,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr auto transform(_Fn&& __f) && { - using _Up = invoke_result_t<_Fn, _Tp>; + using _Up = remove_cv_t>; if (has_value()) return optional<_Up>(_Optional_func<_Fn>{__f}, std::move(**this)); else @@ -1133,7 +1133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr auto transform(_Fn&& __f) const && { - using _Up = invoke_result_t<_Fn, const _Tp>; + using _Up = remove_cv_t>; if (has_value()) return optional<_Up>(_Optional_func<_Fn>{__f}, std::move(**this)); else diff --git a/libstdc++-v3/testsuite/20_util/optional/monadic/pr109242.cc b/libstdc++-v3/testsuite/20_util/optional/monadic/pr109242.cc new file mode 100644 index 00000000000..a25b6251589 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/optional/monadic/pr109242.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++23" } +// { dg-do compile { target c++23 } } + +#include + +// PR libstdc++/109242 +// transform omits required std::remove_cv_t from return optional type + +struct A { }; +struct B { }; +struct C { }; +struct D { }; + +struct F +{ + const A operator()(int&); + const B operator()(const int&); + const C operator()(int&&); + const D operator()(const int&&); +} f; + +std::optional o; +const auto& co = o; + +auto o1 = o.transform(f); +static_assert(std::is_same_v>); + +auto o2 = co.transform(f); +static_assert(std::is_same_v>); + +auto o3 = std::move(o).transform(f); +static_assert(std::is_same_v>); + +auto o4 = std::move(co).transform(f); +static_assert(std::is_same_v>);