From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id C12BD388883D; Fri, 27 May 2022 17:33:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C12BD388883D 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-8424] libstdc++: Implement LWG 3683 for pmr::polymorphic_allocator X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 871aa113666dc787bcc70c94b183e3e420c09e6d X-Git-Newrev: 5647e401bb8656d1d9897c7a536bf00ff50fd20b Message-Id: <20220527173355.C12BD388883D@sourceware.org> Date: Fri, 27 May 2022 17:33:55 +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: Fri, 27 May 2022 17:33:55 -0000 https://gcc.gnu.org/g:5647e401bb8656d1d9897c7a536bf00ff50fd20b commit r12-8424-g5647e401bb8656d1d9897c7a536bf00ff50fd20b Author: Jonathan Wakely Date: Thu May 19 13:26:49 2022 +0100 libstdc++: Implement LWG 3683 for pmr::polymorphic_allocator This issue has recently been moved to Tentatively Ready, and seems uncontroversial. This allows equality comparison with types that are convertible to pmr::polymorphic_allocator, which fail deduction for the existing equality operator. libstdc++-v3/ChangeLog: * include/std/memory_resource (polymorphic_allocator): Add non-template equality operator, as proposed for LWG 3683. * testsuite/20_util/polymorphic_allocator/lwg3683.cc: New test. (cherry picked from commit f13f9c99dbee9c495955a430dd10bdb24a16f24a) Diff: --- libstdc++-v3/include/std/memory_resource | 16 ++++++++++++++++ .../testsuite/20_util/polymorphic_allocator/lwg3683.cc | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource index 4a18d3e8598..5333765de05 100644 --- a/libstdc++-v3/include/std/memory_resource +++ b/libstdc++-v3/include/std/memory_resource @@ -338,6 +338,22 @@ namespace pmr __attribute__((__returns_nonnull__)) { return _M_resource; } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3683. operator== for polymorphic_allocator cannot deduce template arg + [[nodiscard]] + friend bool + operator==(const polymorphic_allocator& __a, + const polymorphic_allocator& __b) noexcept + { return *__a.resource() == *__b.resource(); } + +#if __cpp_impl_three_way_comparison < 201907L + [[nodiscard]] + friend bool + operator!=(const polymorphic_allocator& __a, + const polymorphic_allocator& __b) noexcept + { return !(__a == __b); } +#endif + private: #if ! __cpp_lib_make_obj_using_allocator using __uses_alloc1_ = __uses_alloc1; diff --git a/libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3683.cc b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3683.cc new file mode 100644 index 00000000000..acc91f540b5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3683.cc @@ -0,0 +1,13 @@ +// { dg-do compile { target c++17 } } + +#include + +bool +test_lwg3683(const std::pmr::polymorphic_allocator& a) +{ + if (a == std::pmr::get_default_resource()) + return true; + if (std::pmr::get_default_resource() != a) + return false; + throw a; +}