[libcxx-commits] [PATCH] D137597: [lbc++] Implement the rest of P0600R1 (nodiscard in the library)
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 7 16:02:53 PST 2022
philnik created this revision.
philnik added reviewers: ldionne, Mordante, var-const, huixie90.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137597
Files:
libcxx/docs/ReleaseNotes.rst
libcxx/docs/Status/Cxx20.rst
libcxx/docs/Status/Cxx20Papers.csv
libcxx/include/__memory_resource/memory_resource.h
libcxx/include/__memory_resource/polymorphic_allocator.h
libcxx/test/std/utilities/utility/mem.res/nodiscard.verify.cpp
Index: libcxx/test/std/utilities/utility/mem.res/nodiscard.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/utilities/utility/mem.res/nodiscard.verify.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: c++17 && !stdlib=libc++
+
+// check that 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}}
+
+ std::pmr::polymorphic_allocator<int> poly;
+ poly.allocate(0); // expected-warning {{ignoring return value of function}}
+}
Index: libcxx/include/__memory_resource/polymorphic_allocator.h
===================================================================
--- libcxx/include/__memory_resource/polymorphic_allocator.h
+++ libcxx/include/__memory_resource/polymorphic_allocator.h
@@ -54,7 +54,7 @@
// [mem.poly.allocator.mem]
- _LIBCPP_HIDE_FROM_ABI _ValueType* allocate(size_t __n) {
+ _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _ValueType* allocate(size_t __n) {
if (__n > __max_size()) {
__throw_bad_array_new_length();
}
Index: libcxx/include/__memory_resource/memory_resource.h
===================================================================
--- libcxx/include/__memory_resource/memory_resource.h
+++ libcxx/include/__memory_resource/memory_resource.h
@@ -30,6 +30,7 @@
public:
virtual ~memory_resource();
+ _LIBCPP_NODISCARD_AFTER_CXX17
[[using __gnu__: __returns_nonnull__, __alloc_size__(2), __alloc_align__(3)]] _LIBCPP_HIDE_FROM_ABI void*
allocate(size_t __bytes, size_t __align = __max_align) {
return do_allocate(__bytes, __align);
Index: libcxx/docs/Status/Cxx20Papers.csv
===================================================================
--- libcxx/docs/Status/Cxx20Papers.csv
+++ libcxx/docs/Status/Cxx20Papers.csv
@@ -9,7 +9,7 @@
"`P0439R0 <https://wg21.link/P0439R0>`__","LWG","Make ``std::memory_order``\ a scoped enumeration","Albuquerque","|Complete|",""
"`P0457R2 <https://wg21.link/P0457R2>`__","LWG","String Prefix and Suffix Checking","Albuquerque","|Complete|","6.0"
"`P0550R2 <https://wg21.link/P0550R2>`__","LWG","Transformation Trait ``remove_cvref``\ ","Albuquerque","|Complete|","6.0"
-"`P0600R1 <https://wg21.link/P0600R1>`__","LWG","nodiscard in the Library","Albuquerque","|In Progress| [#note-P0600]_","7.0"
+"`P0600R1 <https://wg21.link/P0600R1>`__","LWG","nodiscard in the Library","Albuquerque","|Complete|","16.0"
"`P0616R0 <https://wg21.link/P0616R0>`__","LWG","de-pessimize legacy <numeric> algorithms with std::move","Albuquerque","|Complete|","12.0"
"`P0653R2 <https://wg21.link/P0653R2>`__","LWG","Utility to convert a pointer to a raw pointer","Albuquerque","|Complete|","6.0"
"`P0718R2 <https://wg21.link/P0718R2>`__","LWG","Atomic shared_ptr","Albuquerque","",""
Index: libcxx/docs/Status/Cxx20.rst
===================================================================
--- libcxx/docs/Status/Cxx20.rst
+++ libcxx/docs/Status/Cxx20.rst
@@ -41,7 +41,6 @@
.. note::
.. [#note-P0591] P0591: The changes in [mem.poly.allocator.mem] are missing.
- .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class] and |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.
Index: libcxx/docs/ReleaseNotes.rst
===================================================================
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -47,6 +47,7 @@
- P0220R1 - Adopt Library Fundamentals V1 TS Components for C++17
- P0482R6 - char8_t: A type for UTF-8 characters and strings
- P2438R2 - ``std::string::substr() &&``
+- P0600R1 - ``nodiscard`` in the library
Improvements and New Features
-----------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137597.473820.patch
Type: text/x-patch
Size: 4534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221108/0033f372/attachment-0001.bin>
More information about the libcxx-commits
mailing list