From 9d7ae0acde2c42b2dac101ec0a51387aa4a8fad9 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 31 Aug 2021 17:46:01 -0400 Subject: [PATCH] [libc++][NFC] Correct comment about P0600 missing node_handle bits Differential Revision: https://reviews.llvm.org/D109027 --- libcxx/docs/Status/Cxx20.rst | 2 +- .../node_handle.nodiscard.verify.cpp | 52 ++++++++++++++++++++++ .../containers/container.node/node_handle.pass.cpp | 30 ++++++------- 3 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 libcxx/test/std/containers/container.node/node_handle.nodiscard.verify.cpp diff --git a/libcxx/docs/Status/Cxx20.rst b/libcxx/docs/Status/Cxx20.rst index 304f69f..7d62339 100644 --- a/libcxx/docs/Status/Cxx20.rst +++ b/libcxx/docs/Status/Cxx20.rst @@ -40,7 +40,7 @@ Paper Status .. note:: - .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class], |sect|\ [mem.poly.allocator.class], and |sect|\ [container.node.overview]. + .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class] and |sect|\ [mem.poly.allocator.class]. .. [#note-P0966] P0966: It was previously erroneously marked as complete in version 8.0. See `bug 45368 `__. .. [#note-P0619] P0619: Only sections D.8, D.9, D.10 and D.13 are implemented. Sections D.4, D.7, D.11, D.12, and D.14 remain undone. .. [#note-P0883] P0883: shared_ptr and floating-point changes weren't applied as they themselves aren't implemented yet. diff --git a/libcxx/test/std/containers/container.node/node_handle.nodiscard.verify.cpp b/libcxx/test/std/containers/container.node/node_handle.nodiscard.verify.cpp new file mode 100644 index 0000000..b94baac --- /dev/null +++ b/libcxx/test/std/containers/container.node/node_handle.nodiscard.verify.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// Make sure the various node handles mark their .empty() method with +// [[nodiscard]] starting with C++20 + +#include +#include +#include +#include + +void test() { + { + std::map::node_type node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::multimap::node_type node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::set node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::multiset node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::unordered_map node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::unordered_multimap node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::unordered_set node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } + { + std::unordered_multiset node; + node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + } +} diff --git a/libcxx/test/std/containers/container.node/node_handle.pass.cpp b/libcxx/test/std/containers/container.node/node_handle.pass.cpp index 91d63cc..1eab904 100644 --- a/libcxx/test/std/containers/container.node/node_handle.pass.cpp +++ b/libcxx/test/std/containers/container.node/node_handle.pass.cpp @@ -15,29 +15,27 @@ #include "test_macros.h" #include "min_allocator.h" -using namespace std; - // [container.node.overview] Table 83. template struct node_compatibility_table { static constexpr bool value = - is_same_v::node_type, typename map::node_type> && - is_same_v::node_type, typename multimap::node_type> && - is_same_v::node_type, typename set::node_type> && - is_same_v::node_type, typename multiset::node_type> && - is_same_v::node_type, typename unordered_map::node_type> && - is_same_v::node_type, typename unordered_multimap::node_type> && - is_same_v::node_type, typename unordered_set::node_type> && - is_same_v::node_type, typename unordered_multiset::node_type>; + std::is_same_v::node_type, typename std::map::node_type> && + std::is_same_v::node_type, typename std::multimap::node_type> && + std::is_same_v::node_type, typename std::set::node_type> && + std::is_same_v::node_type, typename std::multiset::node_type> && + std::is_same_v::node_type, typename std::unordered_map::node_type> && + std::is_same_v::node_type, typename std::unordered_multimap::node_type> && + std::is_same_v::node_type, typename std::unordered_set::node_type> && + std::is_same_v::node_type, typename std::unordered_multiset::node_type>; }; template struct my_hash { using argument_type = T; - using result_type = size_t; + using result_type = std::size_t; my_hash() = default; - size_t operator()(const T&) const {return 0;} + std::size_t operator()(const T&) const {return 0;} }; template struct my_compare @@ -66,9 +64,9 @@ namespace std template <> struct hash { using argument_type = Static; - using result_type = size_t; + using result_type = std::size_t; hash() = default; - size_t operator()(const Static&) const; + std::size_t operator()(const Static&) const; }; } @@ -82,8 +80,8 @@ static_assert(node_compatibility_table< static_assert( node_compatibility_table, my_compare, std::hash, my_hash, std::equal_to, - my_equal, allocator, - allocator>>::value, + my_equal, std::allocator, + std::allocator>>::value, ""); static_assert(node_compatibility_table< -- 2.7.4