[libcxx-commits] [libcxx] [libc++][memory_resource] Applied `[[nodiscard]]` (PR #172134)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 12 00:57:02 PST 2026
================
@@ -6,20 +6,66 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14
+// REQUIRES: std-at-least-c++17
-// check that functions are marked [[nodiscard]] as an extension in C++17
-
-// [[nodiscard]] std::pmr::memory_resource::allocate(size_t, size_t);
-// [[nodiscard]] std::pmr::polymorphic_allocator<T>::allocate(size_t, size_t);
+// check that <memory_resource> functions are marked [[nodiscard]]
#include <memory_resource>
-void f() {
- std::pmr::memory_resource* res = nullptr;
- res->allocate(0); // expected-warning {{ignoring return value of function}}
- res->allocate(0, 1); // expected-warning {{ignoring return value of function}}
+#include "test_macros.h"
+
+void test() {
+ {
+ 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->allocate(1, 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 const attribute}}
----------------
philnik777 wrote:
Just to be clear, I'm not asking for a change here.
https://github.com/llvm/llvm-project/pull/172134
More information about the libcxx-commits
mailing list