From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D0BC1383943F for ; Thu, 19 May 2022 14:32:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0BC1383943F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-_0YnSGkpOfyr1bU9EfJ7IQ-1; Thu, 19 May 2022 10:32:49 -0400 X-MC-Unique: _0YnSGkpOfyr1bU9EfJ7IQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2FD3811E75; Thu, 19 May 2022 14:32:48 +0000 (UTC) Received: from localhost (unknown [10.33.36.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76CEBC15E71; Thu, 19 May 2022 14:32:48 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Implement LWG 3683 for pmr::polymorphic_allocator Date: Thu, 19 May 2022 15:32:47 +0100 Message-Id: <20220519143247.343532-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 14:32:52 -0000 Tested x86_64-linux, pushed to trunk. -- >8 -- 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. --- libstdc++-v3/include/std/memory_resource | 16 ++++++++++++++++ .../20_util/polymorphic_allocator/lwg3683.cc | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/polymorphic_allocator/lwg3683.cc diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource index 88e8abd60fa..745422ad5eb 100644 --- a/libstdc++-v3/include/std/memory_resource +++ b/libstdc++-v3/include/std/memory_resource @@ -356,6 +356,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; +} -- 2.34.3