diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/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 ----------------------------- diff --git a/libcxx/docs/Status/Cxx20.rst b/libcxx/docs/Status/Cxx20.rst --- a/libcxx/docs/Status/Cxx20.rst +++ b/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. diff --git a/libcxx/docs/Status/Cxx20Papers.csv b/libcxx/docs/Status/Cxx20Papers.csv --- a/libcxx/docs/Status/Cxx20Papers.csv +++ b/libcxx/docs/Status/Cxx20Papers.csv @@ -9,7 +9,7 @@ "`P0439R0 `__","LWG","Make ``std::memory_order``\ a scoped enumeration","Albuquerque","|Complete|","" "`P0457R2 `__","LWG","String Prefix and Suffix Checking","Albuquerque","|Complete|","6.0" "`P0550R2 `__","LWG","Transformation Trait ``remove_cvref``\ ","Albuquerque","|Complete|","6.0" -"`P0600R1 `__","LWG","nodiscard in the Library","Albuquerque","|In Progress| [#note-P0600]_","7.0" +"`P0600R1 `__","LWG","nodiscard in the Library","Albuquerque","|Complete|","16.0" "`P0616R0 `__","LWG","de-pessimize legacy algorithms with std::move","Albuquerque","|Complete|","12.0" "`P0653R2 `__","LWG","Utility to convert a pointer to a raw pointer","Albuquerque","|Complete|","6.0" "`P0718R2 `__","LWG","Atomic shared_ptr","Albuquerque","","" diff --git a/libcxx/include/__memory_resource/memory_resource.h b/libcxx/include/__memory_resource/memory_resource.h --- a/libcxx/include/__memory_resource/memory_resource.h +++ b/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); diff --git a/libcxx/include/__memory_resource/polymorphic_allocator.h b/libcxx/include/__memory_resource/polymorphic_allocator.h --- a/libcxx/include/__memory_resource/polymorphic_allocator.h +++ b/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(); } diff --git a/libcxx/test/std/utilities/utility/mem.res/nodiscard.verify.cpp b/libcxx/test/std/utilities/utility/mem.res/nodiscard.verify.cpp new file mode 100644 --- /dev/null +++ b/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 + +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 poly; + poly.allocate(0); // expected-warning {{ignoring return value of function}} +}