[libcxx-commits] [libcxx] [libc++][memory_resource] Applied `[[nodiscard]]` (PR #172134)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 15 08:30:24 PST 2025


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/172134

>From 10c5482198f193ff5e007a1f1fd3a620186f1b23 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 13 Dec 2025 08:40:33 +0200
Subject: [PATCH 1/2] [libc++][memory_resource] Applied `[[nodiscard]]`

Towards #172124
---
 .../__memory_resource/memory_resource.h       | 16 ++--
 .../monotonic_buffer_resource.h               |  7 +-
 .../__memory_resource/polymorphic_allocator.h |  6 +-
 .../synchronized_pool_resource.h              | 10 +-
 .../unsynchronized_pool_resource.h            |  9 +-
 .../memory_resource.nodiscard.verify.cpp      | 91 +++++++++++++++++--
 .../protected_members.verify.cpp              | 12 +--
 7 files changed, 119 insertions(+), 32 deletions(-)

diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h
index f93f10fe21a2d..23ef4f4b77084 100644
--- a/libcxx/include/__memory_resource/memory_resource.h
+++ b/libcxx/include/__memory_resource/memory_resource.h
@@ -42,7 +42,9 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource {
     do_deallocate(__p, __bytes, __align);
   }
 
-  _LIBCPP_HIDE_FROM_ABI bool is_equal(const memory_resource& __other) const noexcept { return do_is_equal(__other); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool is_equal(const memory_resource& __other) const noexcept {
+    return do_is_equal(__other);
+  }
 
 private:
   virtual void* do_allocate(size_t, size_t)                       = 0;
@@ -68,17 +70,19 @@ operator!=(const memory_resource& __lhs, const memory_resource& __rhs) noexcept
 
 // [mem.res.global]
 
-[[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
+[[nodiscard]] [[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
 get_default_resource() noexcept;
 
 [[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
 set_default_resource(memory_resource*) noexcept;
 
-[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
-new_delete_resource() noexcept;
+[[nodiscard]] [[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR
+    _LIBCPP_EXPORTED_FROM_ABI memory_resource*
+    new_delete_resource() noexcept;
 
-[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
-null_memory_resource() noexcept;
+[[nodiscard]] [[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR
+    _LIBCPP_EXPORTED_FROM_ABI memory_resource*
+    null_memory_resource() noexcept;
 
 } // namespace pmr
 
diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h
index 942d490ce3aea..bb2a6749c8ca6 100644
--- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h
+++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h
@@ -93,14 +93,15 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI monotonic_buffer_resour
     }
   }
 
-  _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
 
 protected:
-  void* do_allocate(size_t __bytes, size_t __alignment) override; // key function
+  [[nodiscard]] void* do_allocate(size_t __bytes, size_t __alignment) override; // key function
 
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL void do_deallocate(void*, size_t, size_t) override {}
 
-  _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool
+  do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
     return this == std::addressof(__other);
   }
 
diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h
index 9a351199b5b16..e3d12dcda345c 100644
--- a/libcxx/include/__memory_resource/polymorphic_allocator.h
+++ b/libcxx/include/__memory_resource/polymorphic_allocator.h
@@ -173,11 +173,13 @@ class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator {
     __p->~_Tp();
   }
 
-  _LIBCPP_HIDE_FROM_ABI polymorphic_allocator select_on_container_copy_construction() const noexcept {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI polymorphic_allocator select_on_container_copy_construction() const noexcept {
     return polymorphic_allocator();
   }
 
-  [[__gnu__::__returns_nonnull__]] _LIBCPP_HIDE_FROM_ABI memory_resource* resource() const noexcept { return __res_; }
+  [[nodiscard]] [[__gnu__::__returns_nonnull__]] _LIBCPP_HIDE_FROM_ABI memory_resource* resource() const noexcept {
+    return __res_;
+  }
 
   _LIBCPP_HIDE_FROM_ABI friend bool
   operator==(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h
index bcc1ac4a172e3..f2633e58bd3a2 100644
--- a/libcxx/include/__memory_resource/synchronized_pool_resource.h
+++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h
@@ -56,12 +56,14 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI synchronized_pool_resou
     __unsync_.release();
   }
 
-  _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __unsync_.upstream_resource(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const {
+    return __unsync_.upstream_resource();
+  }
 
-  _LIBCPP_HIDE_FROM_ABI pool_options options() const { return __unsync_.options(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI pool_options options() const { return __unsync_.options(); }
 
 protected:
-  _LIBCPP_HIDE_FROM_ABI_VIRTUAL void* do_allocate(size_t __bytes, size_t __align) override {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL void* do_allocate(size_t __bytes, size_t __align) override {
 #  if _LIBCPP_HAS_THREADS
     unique_lock<mutex> __lk(__mut_);
 #  endif
@@ -75,7 +77,7 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI synchronized_pool_resou
     return __unsync_.deallocate(__p, __bytes, __align);
   }
 
-  bool do_is_equal(const memory_resource& __other) const noexcept override; // key function
+  [[nodiscard]] bool do_is_equal(const memory_resource& __other) const noexcept override; // key function
 
 private:
 #  if _LIBCPP_HAS_THREADS
diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h
index 92da16c559fea..3ea2c0a032f13 100644
--- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h
+++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h
@@ -76,16 +76,17 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI unsynchronized_pool_res
 
   void release();
 
-  _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
 
-  [[__gnu__::__pure__]] pool_options options() const;
+  [[nodiscard]] [[__gnu__::__pure__]] pool_options options() const;
 
 protected:
-  void* do_allocate(size_t __bytes, size_t __align) override; // key function
+  [[nodiscard]] void* do_allocate(size_t __bytes, size_t __align) override; // key function
 
   void do_deallocate(void* __p, size_t __bytes, size_t __align) override;
 
-  _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool
+  do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
     return &__other == this;
   }
 
diff --git a/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp
index 57c3823ba3fdc..4a996c536e057 100644
--- a/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp
@@ -6,20 +6,97 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03, c++11, c++14
+// REQUIRES: std-at-least-c++17
 
 // check that <memory_resource> functions are marked [[nodiscard]]
 
-// clang-format off
-
 #include <memory_resource>
 
 #include "test_macros.h"
 
 void test() {
-  std::pmr::memory_resource* resource = std::pmr::null_memory_resource();
-  resource->allocate(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  {
+    std::pmr::memory_resource* r = std::pmr::null_memory_resource();
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r->allocate(1);
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r->is_equal(*r);
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::pmr::get_default_resource();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::pmr::new_delete_resource();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::pmr::null_memory_resource();
+  }
+
+  {
+    std::pmr::monotonic_buffer_resource r;
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r.upstream_resource();
+
+    struct test_protected : public std::pmr::monotonic_buffer_resource {
+      void test() {
+        std::pmr::monotonic_buffer_resource other;
+
+        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+        do_allocate(94, 82);
+        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+        is_equal(other);
+      }
+    };
+  }
+
+  {
+    std::pmr::polymorphic_allocator<int> a;
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    a.allocate(1);
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    a.select_on_container_copy_construction();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    a.resource();
+  }
+
+  {
+    std::pmr::synchronized_pool_resource r;
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r.upstream_resource();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r.options();
+
+    struct test_protected : public std::pmr::synchronized_pool_resource {
+      void test() {
+        std::pmr::synchronized_pool_resource other;
+
+        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+        do_allocate(94, 82);
+        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+        is_equal(other);
+      }
+    };
+  }
+
+  {
+    std::pmr::unsynchronized_pool_resource r;
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r.upstream_resource();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    r.options();
+
+    struct test_protected : public std::pmr::unsynchronized_pool_resource {
+      void test() {
+        std::pmr::unsynchronized_pool_resource other;
 
-  std::pmr::polymorphic_allocator<int> polymorphic_allocator;
-  polymorphic_allocator.allocate(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+        do_allocate(94, 82);
+        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+        is_equal(other);
+      }
+    };
+  }
 }
diff --git a/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp
index e19d7e93ca354..d546e4f077b34 100644
--- a/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp
+++ b/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp
@@ -29,20 +29,20 @@
 void test() {
   {
     std::pmr::monotonic_buffer_resource m;
-    m.do_allocate(0, 0);            // expected-error{{'do_allocate' is a protected member}}
+    (void)m.do_allocate(0, 0);      // expected-error{{'do_allocate' is a protected member}}
     m.do_deallocate(nullptr, 0, 0); // expected-error{{'do_deallocate' is a protected member}}
-    m.do_is_equal(m);               // expected-error{{'do_is_equal' is a protected member}}
+    (void)m.do_is_equal(m);         // expected-error{{'do_is_equal' is a protected member}}
   }
   {
     std::pmr::synchronized_pool_resource m;
-    m.do_allocate(0, 0);            // expected-error{{'do_allocate' is a protected member}}
+    (void)m.do_allocate(0, 0);      // expected-error{{'do_allocate' is a protected member}}
     m.do_deallocate(nullptr, 0, 0); // expected-error{{'do_deallocate' is a protected member}}
-    m.do_is_equal(m);               // expected-error{{'do_is_equal' is a protected member}}
+    (void)m.do_is_equal(m);         // expected-error{{'do_is_equal' is a protected member}}
   }
   {
     std::pmr::unsynchronized_pool_resource m;
-    m.do_allocate(0, 0);            // expected-error{{'do_allocate' is a protected member}}
+    (void)m.do_allocate(0, 0);      // expected-error{{'do_allocate' is a protected member}}
     m.do_deallocate(nullptr, 0, 0); // expected-error{{'do_deallocate' is a protected member}}
-    m.do_is_equal(m);               // expected-error{{'do_is_equal' is a protected member}}
+    (void)m.do_is_equal(m);         // expected-error{{'do_is_equal' is a protected member}}
   }
 }

>From ef2a79d5523a87fe393d0422a2d60ac18490aeba Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Mon, 15 Dec 2025 18:28:57 +0200
Subject: [PATCH 2/2] Addressed comments

---
 .../__memory_resource/memory_resource.h       | 12 +++---
 .../monotonic_buffer_resource.h               |  5 +--
 .../synchronized_pool_resource.h              |  4 +-
 .../unsynchronized_pool_resource.h            |  7 ++--
 .../memory_resource.nodiscard.verify.cpp      | 39 ++-----------------
 .../protected_members.verify.cpp              | 12 +++---
 6 files changed, 21 insertions(+), 58 deletions(-)

diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h
index 23ef4f4b77084..5b42ae54890b1 100644
--- a/libcxx/include/__memory_resource/memory_resource.h
+++ b/libcxx/include/__memory_resource/memory_resource.h
@@ -70,19 +70,17 @@ operator!=(const memory_resource& __lhs, const memory_resource& __rhs) noexcept
 
 // [mem.res.global]
 
-[[nodiscard]] [[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
+[[nodiscard, __gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
 get_default_resource() noexcept;
 
 [[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
 set_default_resource(memory_resource*) noexcept;
 
-[[nodiscard]] [[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR
-    _LIBCPP_EXPORTED_FROM_ABI memory_resource*
-    new_delete_resource() noexcept;
+[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
+new_delete_resource() noexcept;
 
-[[nodiscard]] [[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR
-    _LIBCPP_EXPORTED_FROM_ABI memory_resource*
-    null_memory_resource() noexcept;
+[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
+null_memory_resource() noexcept;
 
 } // namespace pmr
 
diff --git a/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/libcxx/include/__memory_resource/monotonic_buffer_resource.h
index bb2a6749c8ca6..9c7b07df52f8a 100644
--- a/libcxx/include/__memory_resource/monotonic_buffer_resource.h
+++ b/libcxx/include/__memory_resource/monotonic_buffer_resource.h
@@ -96,12 +96,11 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI monotonic_buffer_resour
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
 
 protected:
-  [[nodiscard]] void* do_allocate(size_t __bytes, size_t __alignment) override; // key function
+  void* do_allocate(size_t __bytes, size_t __alignment) override; // key function
 
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL void do_deallocate(void*, size_t, size_t) override {}
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool
-  do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
+  _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
     return this == std::addressof(__other);
   }
 
diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h
index f2633e58bd3a2..1c929675bb3b3 100644
--- a/libcxx/include/__memory_resource/synchronized_pool_resource.h
+++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h
@@ -63,7 +63,7 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI synchronized_pool_resou
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI pool_options options() const { return __unsync_.options(); }
 
 protected:
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL void* do_allocate(size_t __bytes, size_t __align) override {
+  _LIBCPP_HIDE_FROM_ABI_VIRTUAL void* do_allocate(size_t __bytes, size_t __align) override {
 #  if _LIBCPP_HAS_THREADS
     unique_lock<mutex> __lk(__mut_);
 #  endif
@@ -77,7 +77,7 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI synchronized_pool_resou
     return __unsync_.deallocate(__p, __bytes, __align);
   }
 
-  [[nodiscard]] bool do_is_equal(const memory_resource& __other) const noexcept override; // key function
+  bool do_is_equal(const memory_resource& __other) const noexcept override; // key function
 
 private:
 #  if _LIBCPP_HAS_THREADS
diff --git a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h
index 3ea2c0a032f13..89198a1b7c96e 100644
--- a/libcxx/include/__memory_resource/unsynchronized_pool_resource.h
+++ b/libcxx/include/__memory_resource/unsynchronized_pool_resource.h
@@ -78,15 +78,14 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI unsynchronized_pool_res
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
 
-  [[nodiscard]] [[__gnu__::__pure__]] pool_options options() const;
+  [[__gnu__::__pure__]] pool_options options() const;
 
 protected:
-  [[nodiscard]] void* do_allocate(size_t __bytes, size_t __align) override; // key function
+  void* do_allocate(size_t __bytes, size_t __align) override; // key function
 
   void do_deallocate(void* __p, size_t __bytes, size_t __align) override;
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool
-  do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
+  _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
     return &__other == this;
   }
 
diff --git a/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp
index 4a996c536e057..04fa506c5313b 100644
--- a/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/memory_resource.nodiscard.verify.cpp
@@ -25,9 +25,9 @@ void test() {
 
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     std::pmr::get_default_resource();
-    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    // expected-warning at +1 {{ignoring return value of function declared with const attribute}}
     std::pmr::new_delete_resource();
-    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    // expected-warning at +1 {{ignoring return value of function declared with const attribute}}
     std::pmr::null_memory_resource();
   }
 
@@ -36,17 +36,6 @@ void test() {
 
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     r.upstream_resource();
-
-    struct test_protected : public std::pmr::monotonic_buffer_resource {
-      void test() {
-        std::pmr::monotonic_buffer_resource other;
-
-        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-        do_allocate(94, 82);
-        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-        is_equal(other);
-      }
-    };
   }
 
   {
@@ -67,17 +56,6 @@ void test() {
     r.upstream_resource();
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     r.options();
-
-    struct test_protected : public std::pmr::synchronized_pool_resource {
-      void test() {
-        std::pmr::synchronized_pool_resource other;
-
-        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-        do_allocate(94, 82);
-        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-        is_equal(other);
-      }
-    };
   }
 
   {
@@ -85,18 +63,7 @@ void test() {
 
     // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
     r.upstream_resource();
-    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    // expected-warning at +1 {{ignoring return value of function declared with pure attribute}}
     r.options();
-
-    struct test_protected : public std::pmr::unsynchronized_pool_resource {
-      void test() {
-        std::pmr::unsynchronized_pool_resource other;
-
-        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-        do_allocate(94, 82);
-        // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-        is_equal(other);
-      }
-    };
   }
 }
diff --git a/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp
index d546e4f077b34..e19d7e93ca354 100644
--- a/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp
+++ b/libcxx/test/std/utilities/utility/mem.res/mem.res/mem.res.private/protected_members.verify.cpp
@@ -29,20 +29,20 @@
 void test() {
   {
     std::pmr::monotonic_buffer_resource m;
-    (void)m.do_allocate(0, 0);      // expected-error{{'do_allocate' is a protected member}}
+    m.do_allocate(0, 0);            // expected-error{{'do_allocate' is a protected member}}
     m.do_deallocate(nullptr, 0, 0); // expected-error{{'do_deallocate' is a protected member}}
-    (void)m.do_is_equal(m);         // expected-error{{'do_is_equal' is a protected member}}
+    m.do_is_equal(m);               // expected-error{{'do_is_equal' is a protected member}}
   }
   {
     std::pmr::synchronized_pool_resource m;
-    (void)m.do_allocate(0, 0);      // expected-error{{'do_allocate' is a protected member}}
+    m.do_allocate(0, 0);            // expected-error{{'do_allocate' is a protected member}}
     m.do_deallocate(nullptr, 0, 0); // expected-error{{'do_deallocate' is a protected member}}
-    (void)m.do_is_equal(m);         // expected-error{{'do_is_equal' is a protected member}}
+    m.do_is_equal(m);               // expected-error{{'do_is_equal' is a protected member}}
   }
   {
     std::pmr::unsynchronized_pool_resource m;
-    (void)m.do_allocate(0, 0);      // expected-error{{'do_allocate' is a protected member}}
+    m.do_allocate(0, 0);            // expected-error{{'do_allocate' is a protected member}}
     m.do_deallocate(nullptr, 0, 0); // expected-error{{'do_deallocate' is a protected member}}
-    (void)m.do_is_equal(m);         // expected-error{{'do_is_equal' is a protected member}}
+    m.do_is_equal(m);               // expected-error{{'do_is_equal' is a protected member}}
   }
 }



More information about the libcxx-commits mailing list