public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
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	[thread overview]
Message-ID: <20220519143247.343532-1-jwakely@redhat.com> (raw)

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<polymorphic_allocator>;
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 <memory_resource>
+
+bool
+test_lwg3683(const std::pmr::polymorphic_allocator<int>& a)
+{
+  if (a == std::pmr::get_default_resource())
+    return true;
+  if (std::pmr::get_default_resource() != a)
+    return false;
+  throw a;
+}
-- 
2.34.3


                 reply	other threads:[~2022-05-19 14:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220519143247.343532-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).