[libcxx-commits] [PATCH] D131952: [libc++] Make memory_resource allocate [[nodiscard]]

Jonathan Camilleri via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 16 03:29:26 PDT 2022


J-Camilleri created this revision.
Herald added a project: All.
J-Camilleri requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

P0600: Implement the bit for [mem.res.class]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131952

Files:
  libcxx/docs/Status/Cxx20.rst
  libcxx/include/experimental/memory_resource
  libcxx/test/libcxx/experimental/memory/memory.resource.class/allocate.cxx2a.verify.cpp


Index: libcxx/test/libcxx/experimental/memory/memory.resource.class/allocate.cxx2a.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/experimental/memory/memory.resource.class/allocate.cxx2a.verify.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <experimental/memory_resource>
+
+// memory_resource:
+// void* allocate(size_t __bytes, size_t __align = __max_align)
+
+#include <experimental/memory_resource>
+
+#include "test_memory_resource.h"
+
+int main(int, char**) {
+  NullResource R;
+  R.allocate(3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+
+  return 0;
+}
Index: libcxx/include/experimental/memory_resource
===================================================================
--- libcxx/include/experimental/memory_resource
+++ libcxx/include/experimental/memory_resource
@@ -103,7 +103,7 @@
 public:
     virtual ~memory_resource() = default;
 
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
     void* allocate(size_t __bytes, size_t __align = __max_align)
         { return do_allocate(__bytes, __align); }
 
Index: libcxx/docs/Status/Cxx20.rst
===================================================================
--- libcxx/docs/Status/Cxx20.rst
+++ libcxx/docs/Status/Cxx20.rst
@@ -40,7 +40,7 @@
 
 .. note::
 
-   .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class] and |sect|\ [mem.poly.allocator.class].
+   .. [#note-P0600] P0600: The missing bit in P0600 is |sect|\ [mem.poly.allocator.class].
    .. [#note-P0645] P0645: The paper is implemented but still marked as an incomplete feature
       (the feature-test macro is not set and the libary is only available when built with ``-fexperimental-library``).
       Not yet implemented LWG-issues will cause API and ABI breakage.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131952.452939.patch
Type: text/x-patch
Size: 2293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220816/b3108bf6/attachment.bin>


More information about the libcxx-commits mailing list