From 8e92410ecc86f3ad29e038bf1abad7aa3fc20e7b Mon Sep 17 00:00:00 2001 From: Joe Loser Date: Tue, 12 Oct 2021 22:30:58 -0400 Subject: [PATCH] [libc++][docs] Mark LWG3274 as complete Mark LWG3274 as complete. The feature test macro `__cpp_lib_span` was added in `6d2599e4f776d0cd88438cb82a00c4fc25cc3f67`. https://wg21.link/p1024 mentions marking `span:::empty()` with `[[nodiscard]]` which is not done yet. So, do that and add tests. Reviewed By: ldionne, Quuxplusone, Mordante, #libc Differential Revision: https://reviews.llvm.org/D111516 --- libcxx/docs/Status/Cxx20Issues.csv | 2 +- libcxx/include/span | 14 ++++++------- .../views/span.obs/empty.nodiscard.verify.cpp | 24 ++++++++++++++++++++++ .../std/containers/views/span.obs/empty.pass.cpp | 2 +- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 libcxx/test/std/containers/views/span.obs/empty.nodiscard.verify.cpp diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv index f835afd..6b28620 100644 --- a/libcxx/docs/Status/Cxx20Issues.csv +++ b/libcxx/docs/Status/Cxx20Issues.csv @@ -183,7 +183,7 @@ "`3272 `__","``%I%p``\ should parse/format ``duration``\ since midnight","Belfast","","" "`3259 `__","The definition of *constexpr iterators* should be adjusted","Belfast","","" "`3103 `__","Errors in taking subview of ``span``\ should be ill-formed where possible","Belfast","","" -"`3274 `__","Missing feature test macro for ````\ ","Belfast","","" +"`3274 `__","Missing feature test macro for ````\ ","Belfast","|Complete|","11.0" "`3276 `__","Class ``split_view::outer_iterator::value_type``\ should inherit from ``view_interface``\ ","Belfast","","" "`3277 `__","Pre-increment on prvalues is not a requirement of ``weakly_incrementable``\ ","Belfast","","" "`3149 `__","``DefaultConstructible``\ should require default initialization","Belfast","|Complete|","13.0" diff --git a/libcxx/include/span b/libcxx/include/span index 2f1a19d..29f833f 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -89,7 +89,7 @@ public: // [span.obs], span observers constexpr size_type size() const noexcept; constexpr size_type size_bytes() const noexcept; - constexpr bool empty() const noexcept; + [[nodiscard]] constexpr bool empty() const noexcept; // [span.elem], span element access constexpr reference operator[](size_type idx) const; @@ -330,9 +330,9 @@ public: return {data() + __offset, __count}; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } - _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } + [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept { @@ -501,9 +501,9 @@ public: return {data() + __offset, __count}; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); } - _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); } + [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; } _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept { diff --git a/libcxx/test/std/containers/views/span.obs/empty.nodiscard.verify.cpp b/libcxx/test/std/containers/views/span.obs/empty.nodiscard.verify.cpp new file mode 100644 index 0000000..a6cb479 --- /dev/null +++ b/libcxx/test/std/containers/views/span.obs/empty.nodiscard.verify.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-has-no-incomplete-ranges + +// + +// [[nodiscard]] constexpr bool empty() const noexcept; + +#include + +void test() { + std::span s1; + s1.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + + int arr[] = {1, 2, 3}; + std::span s2{arr}; + s2.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/libcxx/test/std/containers/views/span.obs/empty.pass.cpp b/libcxx/test/std/containers/views/span.obs/empty.pass.cpp index a03db77..5a86aae 100644 --- a/libcxx/test/std/containers/views/span.obs/empty.pass.cpp +++ b/libcxx/test/std/containers/views/span.obs/empty.pass.cpp @@ -13,7 +13,7 @@ // -// constexpr bool empty() const noexcept; +// [[nodiscard]] constexpr bool empty() const noexcept; // -- 2.7.4