* [committed 1/2] libstdc++: Add [[nodiscard]] to iterators and related utilities @ 2021-08-04 11:55 Jonathan Wakely 2021-08-04 11:56 ` [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers Jonathan Wakely 2021-08-05 14:19 ` [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] Jonathan Wakely 0 siblings, 2 replies; 12+ messages in thread From: Jonathan Wakely @ 2021-08-04 11:55 UTC (permalink / raw) To: libstdc++, gcc-patches [-- Attachment #1: Type: text/plain, Size: 252 bytes --] This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 (with some minor corrections). The attribute is added for all modes from C++11 up, using [[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't be used directly. [-- Attachment #2: patch.txt --] [-- Type: text/plain, Size: 78116 bytes --] commit 240b01b0215f9e46ecf04267c8a3faeb19d4fe3c Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Aug 3 18:06:27 2021 libstdc++: Add [[nodiscard]] to iterators and related utilities This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 (with some minor corrections). The attribute is added for all modes from C++11 up, using [[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't be used directly. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (iter_move): Add [[nodiscard]]. * include/bits/range_access.h (begin, end, cbegin, cend) (rbegin, rend, crbegin, crend, size, data, ssize): Likewise. * include/bits/ranges_base.h (ranges::begin, ranges::end) (ranges::cbegin, ranges::cend, ranges::rbegin, ranges::rend) (ranges::crbegin, ranges::crend, ranges::size, ranges::ssize) (ranges::empty, ranges::data, ranges::cdata): Likewise. * include/bits/stl_iterator.h (reverse_iterator, __normal_iterator) (back_insert_iterator, front_insert_iterator, insert_iterator) (move_iterator, move_sentinel, common_iterator) (counted_iterator): Likewise. * include/bits/stl_iterator_base_funcs.h (distance, next, prev): Likewise. * include/bits/stream_iterator.h (istream_iterator) (ostream_iterartor): Likewise. * include/bits/streambuf_iterator.h (istreambuf_iterator) (ostreambuf_iterator): Likewise. * include/std/ranges (views::single, views::iota, views::all) (views::filter, views::transform, views::take, views::take_while) (views::drop, views::drop_while, views::join, views::lazy_split) (views::split, views::counted, views::common, views::reverse) (views::elements): Likewise. * testsuite/20_util/rel_ops.cc: Use -Wno-unused-result. * testsuite/24_iterators/move_iterator/greedy_ops.cc: Likewise. * testsuite/24_iterators/normal_iterator/greedy_ops.cc: Likewise. * testsuite/24_iterators/reverse_iterator/2.cc: Likewise. * testsuite/24_iterators/reverse_iterator/greedy_ops.cc: Likewise. * testsuite/21_strings/basic_string/range_access/char/1.cc: Cast result to void. * testsuite/21_strings/basic_string/range_access/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc: Likewise. * testsuite/23_containers/array/range_access.cc: Likewise. * testsuite/23_containers/deque/range_access.cc: Likewise. * testsuite/23_containers/forward_list/range_access.cc: Likewise. * testsuite/23_containers/list/range_access.cc: Likewise. * testsuite/23_containers/map/range_access.cc: Likewise. * testsuite/23_containers/multimap/range_access.cc: Likewise. * testsuite/23_containers/multiset/range_access.cc: Likewise. * testsuite/23_containers/set/range_access.cc: Likewise. * testsuite/23_containers/unordered_map/range_access.cc: Likewise. * testsuite/23_containers/unordered_multimap/range_access.cc: Likewise. * testsuite/23_containers/unordered_multiset/range_access.cc: Likewise. * testsuite/23_containers/unordered_set/range_access.cc: Likewise. * testsuite/23_containers/vector/range_access.cc: Likewise. * testsuite/24_iterators/customization_points/iter_move.cc: Likewise. * testsuite/24_iterators/istream_iterator/sentinel.cc: Likewise. * testsuite/24_iterators/istreambuf_iterator/sentinel.cc: Likewise. * testsuite/24_iterators/move_iterator/dr2061.cc: Likewise. * testsuite/24_iterators/operations/prev_neg.cc: Likewise. * testsuite/24_iterators/ostreambuf_iterator/2.cc: Likewise. * testsuite/24_iterators/range_access/range_access.cc: Likewise. * testsuite/24_iterators/range_operations/100768.cc: Likewise. * testsuite/26_numerics/valarray/range_access2.cc: Likewise. * testsuite/28_regex/range_access.cc: Likewise. * testsuite/experimental/string_view/range_access/char/1.cc: Likewise. * testsuite/experimental/string_view/range_access/wchar_t/1.cc: Likewise. * testsuite/ext/vstring/range_access.cc: Likewise. * testsuite/std/ranges/adaptors/take.cc: Likewise. * testsuite/std/ranges/p2259.cc: Likewise. diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 9c28ebfb345..739017aaaad 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -120,6 +120,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __type = typename __result<_Tp>::type; template<std::__detail::__dereferenceable _Tp> + [[nodiscard]] constexpr __type<_Tp> operator()(_Tp&& __e) const noexcept(_S_noexcept<_Tp>()) diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h index 71ad28c3ab0..ab2d4f8652c 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -47,6 +47,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto begin(_Container& __cont) -> decltype(__cont.begin()) { return __cont.begin(); } @@ -57,6 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto begin(const _Container& __cont) -> decltype(__cont.begin()) { return __cont.begin(); } @@ -67,6 +69,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto end(_Container& __cont) -> decltype(__cont.end()) { return __cont.end(); } @@ -77,6 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto end(const _Container& __cont) -> decltype(__cont.end()) { return __cont.end(); } @@ -86,6 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template<typename _Tp, size_t _Nm> + [[__nodiscard__]] inline _GLIBCXX14_CONSTEXPR _Tp* begin(_Tp (&__arr)[_Nm]) noexcept { return __arr; } @@ -96,6 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template<typename _Tp, size_t _Nm> + [[__nodiscard__]] inline _GLIBCXX14_CONSTEXPR _Tp* end(_Tp (&__arr)[_Nm]) noexcept { return __arr + _Nm; } @@ -115,6 +121,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline constexpr auto cbegin(const _Container& __cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont)) @@ -126,6 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline constexpr auto cend(const _Container& __cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont)) @@ -137,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rbegin(_Container& __cont) -> decltype(__cont.rbegin()) { return __cont.rbegin(); } @@ -147,6 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rbegin(const _Container& __cont) -> decltype(__cont.rbegin()) { return __cont.rbegin(); } @@ -157,6 +167,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rend(_Container& __cont) -> decltype(__cont.rend()) { return __cont.rend(); } @@ -167,6 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rend(const _Container& __cont) -> decltype(__cont.rend()) { return __cont.rend(); } @@ -177,6 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template<typename _Tp, size_t _Nm> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*> rbegin(_Tp (&__arr)[_Nm]) noexcept { return reverse_iterator<_Tp*>(__arr + _Nm); } @@ -187,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template<typename _Tp, size_t _Nm> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*> rend(_Tp (&__arr)[_Nm]) noexcept { return reverse_iterator<_Tp*>(__arr); } @@ -197,6 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il initializer_list. */ template<typename _Tp> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*> rbegin(initializer_list<_Tp> __il) noexcept { return reverse_iterator<const _Tp*>(__il.end()); } @@ -207,6 +222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il initializer_list. */ template<typename _Tp> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*> rend(initializer_list<_Tp> __il) noexcept { return reverse_iterator<const _Tp*>(__il.begin()); } @@ -217,6 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont)) { return std::rbegin(__cont); } @@ -227,6 +244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template<typename _Container> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto crend(const _Container& __cont) -> decltype(std::rend(__cont)) { return std::rend(__cont); } @@ -241,6 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template <typename _Container> + [[nodiscard]] constexpr auto size(const _Container& __cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size()) @@ -250,6 +269,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief Return the size of an array. */ template <typename _Tp, size_t _Nm> + [[nodiscard]] constexpr size_t size(const _Tp (&)[_Nm]) noexcept { return _Nm; } @@ -286,6 +306,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template <typename _Container> + [[nodiscard]] constexpr auto data(_Container& __cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data()) @@ -296,6 +317,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template <typename _Container> + [[nodiscard]] constexpr auto data(const _Container& __cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data()) @@ -306,6 +328,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __array Array. */ template <typename _Tp, size_t _Nm> + [[nodiscard]] constexpr _Tp* data(_Tp (&__array)[_Nm]) noexcept { return __array; } @@ -315,6 +338,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il Initializer list. */ template <typename _Tp> + [[nodiscard]] constexpr const _Tp* data(initializer_list<_Tp> __il) noexcept { return __il.begin(); } @@ -322,6 +346,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L #define __cpp_lib_ssize 201902L template<typename _Container> + [[nodiscard]] constexpr auto ssize(const _Container& __cont) noexcept(noexcept(__cont.size())) @@ -332,6 +357,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, ptrdiff_t _Num> + [[nodiscard]] constexpr ptrdiff_t ssize(const _Tp (&)[_Num]) noexcept { return _Num; } diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 9d749c8d9b7..614b6edf9df 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -110,6 +110,7 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires is_array_v<remove_reference_t<_Tp>> || __member_begin<_Tp> || __adl_begin<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -161,6 +162,7 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_end<_Tp> || __adl_end<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -192,6 +194,7 @@ namespace ranges struct _CBegin { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e)))) @@ -204,6 +207,7 @@ namespace ranges struct _CEnd final { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e)))) @@ -263,6 +267,7 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_rbegin<_Tp> || __adl_rbegin<_Tp> || __reversable<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) @@ -321,6 +326,7 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_rend<_Tp> || __adl_rend<_Tp> || __reversable<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) @@ -337,6 +343,7 @@ namespace ranges struct _CRBegin { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e)))) @@ -349,6 +356,7 @@ namespace ranges struct _CREnd { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e)))) @@ -408,6 +416,7 @@ namespace ranges template<typename _Tp> requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_size<_Tp> || __adl_size<_Tp> || __sentinel_size<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -428,6 +437,7 @@ namespace ranges // 3403. Domain of ranges::ssize(E) doesn't match ranges::size(E) template<typename _Tp> requires requires (_Tp& __t) { _Size{}(__t); } + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(_Size{}(__t))) { @@ -487,6 +497,7 @@ namespace ranges template<typename _Tp> requires __member_empty<_Tp> || __size0_empty<_Tp> || __eq_iter_empty<_Tp> + [[nodiscard]] constexpr bool operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -528,6 +539,7 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_data<_Tp> || __begin_data<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>()) { @@ -541,6 +553,7 @@ namespace ranges struct _CData { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e)))) @@ -782,6 +795,7 @@ namespace ranges struct __distance_fn final { template<input_or_output_iterator _It, sentinel_for<_It> _Sent> + [[nodiscard]] constexpr iter_difference_t<_It> operator()(_It __first, _Sent __last) const { @@ -800,6 +814,7 @@ namespace ranges } template<range _Range> + [[nodiscard]] constexpr range_difference_t<_Range> operator()(_Range&& __r) const { @@ -817,6 +832,7 @@ namespace ranges struct __next_fn final { template<input_or_output_iterator _It> + [[nodiscard]] constexpr _It operator()(_It __x) const { @@ -825,6 +841,7 @@ namespace ranges } template<input_or_output_iterator _It> + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n) const { @@ -833,6 +850,7 @@ namespace ranges } template<input_or_output_iterator _It, sentinel_for<_It> _Sent> + [[nodiscard]] constexpr _It operator()(_It __x, _Sent __bound) const { @@ -841,6 +859,7 @@ namespace ranges } template<input_or_output_iterator _It, sentinel_for<_It> _Sent> + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n, _Sent __bound) const { @@ -856,6 +875,7 @@ namespace ranges struct __prev_fn final { template<bidirectional_iterator _It> + [[nodiscard]] constexpr _It operator()(_It __x) const { @@ -864,6 +884,7 @@ namespace ranges } template<bidirectional_iterator _It> + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n) const { @@ -872,6 +893,7 @@ namespace ranges } template<bidirectional_iterator _It> + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n, _It __bound) const { diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 7fe727d8093..3773d600b8f 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -223,6 +223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @return @c current, the %iterator used for underlying work. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR iterator_type base() const { return current; } @@ -237,6 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @c *x remains valid after @c x has been modified or * destroyed. This is a bug: http://gcc.gnu.org/PR51823 */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reference operator*() const { @@ -249,6 +251,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * This requires that @c --current is dereferenceable. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR pointer operator->() const #if __cplusplus > 201703L && __cpp_concepts >= 201907L @@ -318,6 +321,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reverse_iterator operator+(difference_type __n) const { return reverse_iterator(current - __n); } @@ -340,6 +344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reverse_iterator operator-(difference_type __n) const { return reverse_iterator(current + __n); } @@ -362,11 +367,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const { return *(*this + __n); } #if __cplusplus > 201703L && __cpp_lib_concepts + [[nodiscard]] friend constexpr iter_rvalue_reference_t<_Iterator> iter_move(const reverse_iterator& __i) noexcept(is_nothrow_copy_constructible_v<_Iterator> @@ -415,36 +422,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ #if __cplusplus <= 201703L || ! defined __cpp_lib_concepts template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator==(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __x.base() == __y.base(); } template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator<(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y.base() < __x.base(); } template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator!=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__x == __y); } template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y < __x; } template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator<=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__y < __x); } template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) @@ -454,24 +467,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 280. Comparison of reverse_iterator to const reverse_iterator. template<typename _IteratorL, typename _IteratorR> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator==(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() == __y.base(); } template<typename _IteratorL, typename _IteratorR> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator<(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() > __y.base(); } template<typename _IteratorL, typename _IteratorR> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator!=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() != __y.base(); } template<typename _IteratorL, typename _IteratorR> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -484,12 +501,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() >= __y.base(); } template<typename _IteratorL, typename _IteratorR> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() <= __y.base(); } #else // C++20 template<typename _IteratorL, typename _IteratorR> + [[nodiscard]] constexpr bool operator==(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -497,6 +516,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() == __y.base(); } template<typename _IteratorL, typename _IteratorR> + [[nodiscard]] constexpr bool operator!=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -504,6 +524,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() != __y.base(); } template<typename _IteratorL, typename _IteratorR> + [[nodiscard]] constexpr bool operator<(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -511,6 +532,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() > __y.base(); } template<typename _IteratorL, typename _IteratorR> + [[nodiscard]] constexpr bool operator>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -518,6 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() < __y.base(); } template<typename _IteratorL, typename _IteratorR> + [[nodiscard]] constexpr bool operator<=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -525,6 +548,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() >= __y.base(); } template<typename _IteratorL, typename _IteratorR> + [[nodiscard]] constexpr bool operator>=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -533,6 +557,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _IteratorL, three_way_comparable_with<_IteratorL> _IteratorR> + [[nodiscard]] constexpr compare_three_way_result_t<_IteratorL, _IteratorR> operator<=>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -556,6 +581,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 685. reverse_iterator/move_iterator difference has invalid signatures template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto operator-(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -564,6 +590,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template<typename _Iterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> operator+(typename reverse_iterator<_Iterator>::difference_type __n, const reverse_iterator<_Iterator>& __x) @@ -583,6 +610,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 2285. make_reverse_iterator /// Generator function for reverse_iterator. template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> make_reverse_iterator(_Iterator __i) { return reverse_iterator<_Iterator>(__i); } @@ -683,7 +711,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// Simply returns *this. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR back_insert_iterator& operator*() { return *this; } @@ -713,7 +741,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * types for you. */ template<typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline back_insert_iterator<_Container> back_inserter(_Container& __x) { return back_insert_iterator<_Container>(__x); } @@ -784,7 +812,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// Simply returns *this. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR front_insert_iterator& operator*() { return *this; } @@ -814,7 +842,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * types for you. */ template<typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline front_insert_iterator<_Container> front_inserter(_Container& __x) { return front_insert_iterator<_Container>(__x); } @@ -914,7 +942,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// Simply returns *this. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR insert_iterator& operator*() { return *this; } @@ -946,11 +974,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ #if __cplusplus > 201703L && defined __cpp_lib_concepts template<typename _Container> + [[nodiscard]] constexpr insert_iterator<_Container> inserter(_Container& __x, std::__detail::__range_iter_t<_Container> __i) { return insert_iterator<_Container>(__x, __i); } #else template<typename _Container> + _GLIBCXX_NODISCARD inline insert_iterator<_Container> inserter(_Container& __x, typename _Container::iterator __i) { return insert_iterator<_Container>(__x, __i); } @@ -1090,6 +1120,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _IteratorL, typename _IteratorR, typename _Container> requires requires (_IteratorL __lhs, _IteratorR __rhs) { { __lhs == __rhs } -> std::convertible_to<bool>; } + [[nodiscard]] constexpr bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1097,6 +1128,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() == __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> + [[nodiscard]] constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1105,7 +1137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #else // Forward iterator requirements template<typename _IteratorL, typename _IteratorR, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1113,7 +1145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() == __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1121,7 +1153,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() == __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1129,7 +1161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() != __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1138,6 +1170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Random access iterator requirements template<typename _IteratorL, typename _IteratorR, typename _Container> + _GLIBCXX_NODISCARD inline bool operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1145,7 +1178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() < __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator<(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1153,6 +1186,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() < __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> + _GLIBCXX_NODISCARD inline bool operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1160,7 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() > __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator>(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1168,6 +1202,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() > __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> + _GLIBCXX_NODISCARD inline bool operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1175,7 +1210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() <= __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1183,6 +1218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() <= __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> + _GLIBCXX_NODISCARD inline bool operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1190,7 +1226,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() >= __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1205,7 +1241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _IteratorL, typename _IteratorR, typename _Container> #if __cplusplus >= 201103L // DR 685. - _GLIBCXX20_CONSTEXPR + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline auto operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept @@ -1218,7 +1254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() - __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline typename __normal_iterator<_Iterator, _Container>::difference_type operator-(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1226,7 +1262,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() - __rhs.base(); } template<typename _Iterator, typename _Container> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline __normal_iterator<_Iterator, _Container> operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, const __normal_iterator<_Iterator, _Container>& __i) @@ -1284,6 +1320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr _Sent base() const noexcept(is_nothrow_copy_constructible_v<_Sent>) @@ -1397,19 +1434,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #if __cplusplus <= 201703L + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR iterator_type base() const { return _M_current; } #else + [[nodiscard]] constexpr const iterator_type& base() const & noexcept { return _M_current; } + [[nodiscard]] constexpr iterator_type base() && { return std::move(_M_current); } #endif + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference operator*() const #if __cplusplus > 201703L && __cpp_lib_concepts @@ -1418,6 +1459,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return static_cast<reference>(*_M_current); } #endif + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR pointer operator->() const { return _M_current; } @@ -1458,6 +1500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __tmp; } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR move_iterator operator+(difference_type __n) const { return move_iterator(_M_current + __n); } @@ -1469,6 +1512,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR move_iterator operator-(difference_type __n) const { return move_iterator(_M_current - __n); } @@ -1480,6 +1524,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const #if __cplusplus > 201703L && __cpp_lib_concepts @@ -1490,20 +1535,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L && __cpp_lib_concepts template<sentinel_for<_Iterator> _Sent> + [[nodiscard]] friend constexpr bool operator==(const move_iterator& __x, const move_sentinel<_Sent>& __y) { return __x.base() == __y.base(); } template<sized_sentinel_for<_Iterator> _Sent> + [[nodiscard]] friend constexpr iter_difference_t<_Iterator> operator-(const move_sentinel<_Sent>& __x, const move_iterator& __y) { return __x.base() - __y.base(); } template<sized_sentinel_for<_Iterator> _Sent> + [[nodiscard]] friend constexpr iter_difference_t<_Iterator> operator-(const move_iterator& __x, const move_sentinel<_Sent>& __y) { return __x.base() - __y.base(); } + [[nodiscard]] friend constexpr iter_rvalue_reference_t<_Iterator> iter_move(const move_iterator& __i) noexcept(noexcept(ranges::iter_move(__i._M_current))) @@ -1518,6 +1567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator==(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1529,12 +1579,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_three_way_comparison template<typename _IteratorL, three_way_comparable_with<_IteratorL> _IteratorR> + [[__nodiscard__]] constexpr compare_three_way_result_t<_IteratorL, _IteratorR> operator<=>(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __x.base() <=> __y.base(); } #else template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator!=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1542,6 +1594,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1551,6 +1604,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() < __y.base(); } template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1560,6 +1614,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !(__y < __x); } template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1569,6 +1624,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __y < __x; } template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1586,36 +1642,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // prefer them to greedy unconstrained function templates. template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator==(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __x.base() == __y.base(); } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator!=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__x == __y); } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __x.base() < __y.base(); } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__y < __x); } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __y < __x; } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) @@ -1624,6 +1686,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 685. template<typename _IteratorL, typename _IteratorR> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto operator-(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1631,12 +1694,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() - __y.base(); } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> operator+(typename move_iterator<_Iterator>::difference_type __n, const move_iterator<_Iterator>& __x) { return __x + __n; } template<typename _Iterator> + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> make_move_iterator(_Iterator __i) { return move_iterator<_Iterator>(std::move(__i)); } @@ -1857,6 +1922,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + [[nodiscard]] decltype(auto) operator*() { @@ -1864,6 +1930,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_it; } + [[nodiscard]] decltype(auto) operator*() const requires __detail::__dereferenceable<const _It> { @@ -1871,6 +1938,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_it; } + [[nodiscard]] decltype(auto) operator->() const requires __detail::__common_iter_has_arrow<_It> { @@ -1916,6 +1984,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _It2, sentinel_for<_It> _Sent2> requires sentinel_for<_Sent, _It2> + [[nodiscard]] friend bool operator==(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) @@ -1938,6 +2007,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _It2, sentinel_for<_It> _Sent2> requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2> + [[nodiscard]] friend bool operator==(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) @@ -1961,6 +2031,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2> requires sized_sentinel_for<_Sent, _It2> + [[nodiscard]] friend iter_difference_t<_It2> operator-(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) @@ -1982,6 +2053,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + [[nodiscard]] friend iter_rvalue_reference_t<_It> iter_move(const common_iterator& __i) noexcept(noexcept(ranges::iter_move(std::declval<const _It&>()))) @@ -2132,18 +2204,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr const _It& base() const & noexcept { return _M_current; } + [[nodiscard]] constexpr _It base() && noexcept(is_nothrow_move_constructible_v<_It>) { return std::move(_M_current); } + [[nodiscard]] constexpr iter_difference_t<_It> count() const noexcept { return _M_length; } + [[nodiscard]] constexpr decltype(auto) operator*() noexcept(noexcept(*_M_current)) @@ -2152,6 +2228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_current; } + [[nodiscard]] constexpr decltype(auto) operator*() const noexcept(noexcept(*_M_current)) @@ -2161,6 +2238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_current; } + [[nodiscard]] constexpr auto operator->() const noexcept requires contiguous_iterator<_It> @@ -2214,11 +2292,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __tmp; } + [[nodiscard]] constexpr counted_iterator operator+(iter_difference_t<_It> __n) const requires random_access_iterator<_It> { return counted_iterator(_M_current + __n, _M_length - __n); } + [[nodiscard]] friend constexpr counted_iterator operator+(iter_difference_t<_It> __n, const counted_iterator& __x) requires random_access_iterator<_It> @@ -2234,21 +2314,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr counted_iterator operator-(iter_difference_t<_It> __n) const requires random_access_iterator<_It> { return counted_iterator(_M_current - __n, _M_length + __n); } template<common_with<_It> _It2> + [[nodiscard]] friend constexpr iter_difference_t<_It2> operator-(const counted_iterator& __x, const counted_iterator<_It2>& __y) { return __y._M_length - __x._M_length; } + [[nodiscard]] friend constexpr iter_difference_t<_It> operator-(const counted_iterator& __x, default_sentinel_t) { return -__x._M_length; } + [[nodiscard]] friend constexpr iter_difference_t<_It> operator-(default_sentinel_t, const counted_iterator& __y) { return __y._M_length; } @@ -2263,6 +2347,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr decltype(auto) operator[](iter_difference_t<_It> __n) const noexcept(noexcept(_M_current[__n])) @@ -2273,21 +2358,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<common_with<_It> _It2> + [[nodiscard]] friend constexpr bool operator==(const counted_iterator& __x, const counted_iterator<_It2>& __y) { return __x._M_length == __y._M_length; } + [[nodiscard]] friend constexpr bool operator==(const counted_iterator& __x, default_sentinel_t) { return __x._M_length == 0; } template<common_with<_It> _It2> + [[nodiscard]] friend constexpr strong_ordering operator<=>(const counted_iterator& __x, const counted_iterator<_It2>& __y) { return __y._M_length <=> __x._M_length; } + [[nodiscard]] friend constexpr iter_rvalue_reference_t<_It> iter_move(const counted_iterator& __i) noexcept(noexcept(ranges::iter_move(__i._M_current))) diff --git a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h index fa8474f23c6..e5afab7f4fd 100644 --- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h +++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h @@ -133,6 +133,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER * and are constant time. For other %iterator classes they are linear time. */ template<typename _InputIterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR typename iterator_traits<_InputIterator>::difference_type distance(_InputIterator __first, _InputIterator __last) @@ -209,6 +210,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER #if __cplusplus >= 201103L template<typename _InputIterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR _InputIterator next(_InputIterator __x, typename iterator_traits<_InputIterator>::difference_type __n = 1) @@ -220,6 +222,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER } template<typename _BidirectionalIterator> + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR _BidirectionalIterator prev(_BidirectionalIterator __x, typename iterator_traits<_BidirectionalIterator>::difference_type __n = 1) diff --git a/libstdc++-v3/include/bits/stream_iterator.h b/libstdc++-v3/include/bits/stream_iterator.h index d07474d4996..d74c158f342 100644 --- a/libstdc++-v3/include/bits/stream_iterator.h +++ b/libstdc++-v3/include/bits/stream_iterator.h @@ -89,6 +89,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~istream_iterator() = default; #endif + _GLIBCXX_NODISCARD const _Tp& operator*() const { @@ -98,6 +99,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _M_value; } + _GLIBCXX_NODISCARD const _Tp* operator->() const { return std::__addressof((operator*())); } @@ -143,17 +145,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Return true if the iterators refer to the same stream, /// or are both at end-of-stream. + _GLIBCXX_NODISCARD friend bool operator==(const istream_iterator& __x, const istream_iterator& __y) { return __x._M_equal(__y); } +#if __cpp_impl_three_way_comparison < 201907L /// Return true if the iterators refer to different streams, /// or if one is at end-of-stream and the other is not. + _GLIBCXX_NODISCARD friend bool operator!=(const istream_iterator& __x, const istream_iterator& __y) { return !__x._M_equal(__y); } +#endif #if __cplusplus > 201703L && __cpp_lib_concepts + [[nodiscard]] friend bool operator==(const istream_iterator& __i, default_sentinel_t) { return !__i._M_stream; } @@ -231,6 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + _GLIBCXX_NODISCARD ostream_iterator& operator*() { return *this; } diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index cda596af40f..0a77d1a3da4 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -141,6 +141,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Return the current character pointed to by iterator. This returns /// streambuf.sgetc(). It cannot be assigned. NB: The result of /// operator*() on an end of stream is undefined. + _GLIBCXX_NODISCARD char_type operator*() const { @@ -189,6 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 110 istreambuf_iterator::equal not const // NB: there is also number 111 (NAD) relevant to this function. /// Return true both iterators are end or both are not end. + _GLIBCXX_NODISCARD bool equal(const istreambuf_iterator& __b) const { return _M_at_eof() == __b._M_at_eof(); } @@ -215,6 +217,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #if __cplusplus > 201703L && __cpp_lib_concepts + [[nodiscard]] friend bool operator==(const istreambuf_iterator& __i, default_sentinel_t __s) { return __i._M_at_eof(); } @@ -222,16 +225,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template<typename _CharT, typename _Traits> + _GLIBCXX_NODISCARD inline bool operator==(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) { return __a.equal(__b); } +#if __cpp_impl_three_way_comparison < 201907L template<typename _CharT, typename _Traits> + _GLIBCXX_NODISCARD inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) { return !__a.equal(__b); } +#endif /// Provides output iterator semantics for streambufs. template<typename _CharT, typename _Traits> @@ -288,6 +295,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } /// Return *this. + _GLIBCXX_NODISCARD ostreambuf_iterator& operator*() { return *this; } @@ -303,6 +311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return *this; } /// Return true if previous operator=() failed. + _GLIBCXX_NODISCARD bool failed() const _GLIBCXX_USE_NOEXCEPT { return _M_failed; } diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 5bdcd445a9e..03a3778bb52 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -645,6 +645,7 @@ namespace views struct _Single { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(single_view<decay_t<_Tp>>(std::forward<_Tp>(__e)))) @@ -656,11 +657,13 @@ namespace views struct _Iota { template<typename _Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const { return iota_view(std::forward<_Tp>(__e)); } template<typename _Tp, typename _Up> + [[nodiscard]] constexpr auto operator()(_Tp&& __e, _Up&& __f) const { return iota_view(std::forward<_Tp>(__e), std::forward<_Up>(__f)); } @@ -1123,6 +1126,7 @@ namespace views::__adaptor requires view<decay_t<_Range>> || __detail::__can_ref_view<_Range> || __detail::__can_subrange<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const noexcept(_S_noexcept<_Range>()) @@ -1549,6 +1553,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pred> requires __detail::__can_filter_view<_Range, _Pred> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const { @@ -1926,6 +1931,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Fp> requires __detail::__can_transform_view<_Range, _Fp> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Fp&& __f) const { @@ -2107,6 +2113,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Tp> requires __detail::__can_take_view<_Range, _Tp> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Tp&& __n) const { @@ -2234,6 +2241,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pred> requires __detail::__can_take_while_view<_Range, _Pred> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const { @@ -2354,6 +2362,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Tp> requires __detail::__can_drop_view<_Range, _Tp> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Tp&& __n) const { @@ -2442,6 +2451,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pred> requires __detail::__can_drop_while_view<_Range, _Pred> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const { @@ -2804,6 +2814,7 @@ namespace views::__adaptor { template<viewable_range _Range> requires __detail::__can_join_view<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { @@ -3255,6 +3266,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pattern> requires __detail::__can_lazy_split_view<_Range, _Pattern> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pattern&& __f) const { @@ -3463,6 +3475,7 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pattern> requires __detail::__can_split_view<_Range, _Pattern> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pattern&& __f) const { @@ -3484,6 +3497,7 @@ namespace views::__adaptor struct _Counted { template<input_or_output_iterator _Iter> + [[nodiscard]] constexpr auto operator()(_Iter __i, iter_difference_t<_Iter> __n) const { @@ -3605,6 +3619,7 @@ namespace views::__adaptor template<viewable_range _Range> requires __detail::__already_common<_Range> || __detail::__can_common_view<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { @@ -3727,6 +3742,7 @@ namespace views::__adaptor requires __detail::__is_reverse_view<remove_cvref_t<_Range>> || __detail::__is_reversible_subrange<remove_cvref_t<_Range>> || __detail::__can_reverse_view<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { @@ -4125,6 +4141,7 @@ namespace views::__adaptor { template<viewable_range _Range> requires __detail::__can_elements_view<_Nm, _Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { diff --git a/libstdc++-v3/testsuite/20_util/rel_ops.cc b/libstdc++-v3/testsuite/20_util/rel_ops.cc index 4726462e64e..dd2c14650ae 100644 --- a/libstdc++-v3/testsuite/20_util/rel_ops.cc +++ b/libstdc++-v3/testsuite/20_util/rel_ops.cc @@ -17,6 +17,8 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. +// { dg-options "-Wno-unused-result" } + // 20.2.1 Operators #include <utility> diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc index 90574d2a811..d37b1cb4c4e 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc @@ -25,6 +25,6 @@ void test01() { std::string s("Hello, World!"); - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc index beab3110ca2..56169150089 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc @@ -26,7 +26,7 @@ test01() { #ifdef _GLIBCXX_USE_WCHAR_T std::wstring ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); + (void) std::begin(ws); + (void) std::end(ws); #endif } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc index 856aafde552..4a3595663b8 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc @@ -25,10 +25,10 @@ void test01() { std::string_view s("Hello, World!"); - std::begin(s); - std::end(s); - std::rbegin(s); - std::rend(s); + (void) std::begin(s); + (void) std::end(s); + (void) std::rbegin(s); + (void) std::rend(s); } void diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc index c6d83c47bfd..f8ecd1a84cd 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc @@ -25,10 +25,10 @@ void test01() { std::wstring_view ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); - std::rbegin(ws); - std::rend(ws); + (void) std::begin(ws); + (void) std::end(ws); + (void) std::rbegin(ws); + (void) std::rend(ws); } void diff --git a/libstdc++-v3/testsuite/23_containers/array/range_access.cc b/libstdc++-v3/testsuite/23_containers/array/range_access.cc index 38116888a6c..807ccdb2b01 100644 --- a/libstdc++-v3/testsuite/23_containers/array/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/array/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::array<int, 3> a{{1, 2, 3}}; - std::begin(a); - std::end(a); + (void) std::begin(a); + (void) std::end(a); } diff --git a/libstdc++-v3/testsuite/23_containers/deque/range_access.cc b/libstdc++-v3/testsuite/23_containers/deque/range_access.cc index fed56a48414..990fc0d573b 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::deque<int> d{1, 2, 3}; - std::begin(d); - std::end(d); + (void) std::begin(d); + (void) std::end(d); } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc b/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc index 0b70ff02131..6398240e126 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::forward_list<int> fl{1, 2, 3}; - std::begin(fl); - std::end(fl); + (void) std::begin(fl); + (void) std::end(fl); } diff --git a/libstdc++-v3/testsuite/23_containers/list/range_access.cc b/libstdc++-v3/testsuite/23_containers/list/range_access.cc index de845d446f0..15047ec755d 100644 --- a/libstdc++-v3/testsuite/23_containers/list/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/list/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::list<int> l{1, 2, 3}; - std::begin(l); - std::end(l); + (void) std::begin(l); + (void) std::end(l); } diff --git a/libstdc++-v3/testsuite/23_containers/map/range_access.cc b/libstdc++-v3/testsuite/23_containers/map/range_access.cc index dc0bdbb9a74..3c6b00128ca 100644 --- a/libstdc++-v3/testsuite/23_containers/map/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/map/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::map<int, double> m{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(m); - std::end(m); + (void) std::begin(m); + (void) std::end(m); } diff --git a/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc b/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc index 32ffa3b2651..020a7a9e627 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::multimap<int, double> mm{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(mm); - std::end(mm); + (void) std::begin(mm); + (void) std::end(mm); } diff --git a/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc b/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc index 2d08ba40a59..7e66bfa24aa 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::multiset<int> ms{1, 2, 3}; - std::begin(ms); - std::end(ms); + (void) std::begin(ms); + (void) std::end(ms); } diff --git a/libstdc++-v3/testsuite/23_containers/set/range_access.cc b/libstdc++-v3/testsuite/23_containers/set/range_access.cc index 35703e2a7be..66099b39df4 100644 --- a/libstdc++-v3/testsuite/23_containers/set/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/set/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::set<int> s{1, 2, 3}; - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc index edb06d06894..ad20c1da942 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_map<int, double> um{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(um); - std::end(um); + (void) std::begin(um); + (void) std::end(um); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc index e19e825a042..4bb126e34f9 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_multimap<int, double> umm{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(umm); - std::end(umm); + (void) std::begin(umm); + (void) std::end(umm); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc index 574012bee32..899b74af35c 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_multiset<int> ums{1, 2, 3}; - std::begin(ums); - std::end(ums); + (void) std::begin(ums); + (void) std::end(ums); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc index 033653a37ec..4f9e8857113 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_set<int> us{1, 2, 3}; - std::begin(us); - std::end(us); + (void) std::begin(us); + (void) std::end(us); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/range_access.cc b/libstdc++-v3/testsuite/23_containers/vector/range_access.cc index a36975cac72..0dd761b71f1 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/range_access.cc @@ -25,10 +25,10 @@ void test01() { std::vector<double> v{1.0, 2.0, 3.0}; - std::begin(v); - std::end(v); + (void) std::begin(v); + (void) std::end(v); std::vector<bool> vb{true, false, true}; - std::begin(vb); - std::end(vb); + (void) std::begin(vb); + (void) std::end(vb); } diff --git a/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc b/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc index a43448581f3..40a084b918c 100644 --- a/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc +++ b/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc @@ -51,7 +51,7 @@ constexpr bool test_X(int i, int j) { X x1{i}, x2{j}; - std::ranges::iter_move(&x1); // no-op + (void) std::ranges::iter_move(&x1); // no-op x1 = std::ranges::iter_move(&x2); return x1.value == j && x2.value == -1; } diff --git a/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc b/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc index 7e1fd173877..f8f16375bf0 100644 --- a/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc +++ b/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc @@ -43,9 +43,9 @@ test02() VERIFY( iter != std::default_sentinel ); VERIFY( std::default_sentinel != iter ); - *iter++; - *iter++; - *iter++; + (void) *iter++; + (void) *iter++; + (void) *iter++; VERIFY( iter == std::default_sentinel ); VERIFY( std::default_sentinel == iter ); } diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc index 4961ddaf793..b7cdd44677d 100644 --- a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc +++ b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc @@ -41,7 +41,7 @@ test02() VERIFY( iter != std::default_sentinel ); VERIFY( std::default_sentinel != iter ); - std::next(iter, 3); + (void) std::next(iter, 3); VERIFY( iter == std::default_sentinel ); VERIFY( std::default_sentinel == iter ); } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc index 0af4b16b7f4..c9bd3d677e5 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc @@ -23,6 +23,6 @@ void test01() { int a[] = { 1, 2, 3, 4 }; - std::make_move_iterator(a + 4); - std::make_move_iterator(a); + (void) std::make_move_iterator(a + 4); + (void) std::make_move_iterator(a); } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc index 93b3d7dbcd4..ce50e34a5a6 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc @@ -1,4 +1,6 @@ // { dg-do compile { target c++11 } } +// { dg-options "-Wno-unused-result" } + // Copyright (C) 2010-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free diff --git a/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc index 557dfacbf24..29ff7266d07 100644 --- a/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc +++ b/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc @@ -1,4 +1,6 @@ // { dg-do compile } +// { dg-options "-Wno-unused-result" } + // Copyright (C) 2010-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -33,7 +35,7 @@ void test01() greedy_ops::C> iterator_type; iterator_type it(0); - + it == it; it != it; it < it; @@ -45,8 +47,8 @@ void test01() 1 + it; } -int main() -{ +int main() +{ test01(); return 0; } diff --git a/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc b/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc index 1d421bbcb2d..cafafc4b651 100644 --- a/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc +++ b/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc @@ -37,6 +37,6 @@ void test02() { const Y array[1] = { }; - std::prev(array + 1); + (void) std::prev(array + 1); // { dg-error "forward_iterator" "" { target *-*-* } 223 } } diff --git a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc index 847f4352739..a962cd58236 100644 --- a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc +++ b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc @@ -45,7 +45,7 @@ void test02(void) VERIFY( !ostrb_it01.failed() ); ostrb_it01 = 'a'; VERIFY( !ostrb_it01.failed() ); - *ostrb_it01; + (void) *ostrb_it01; VERIFY( !ostrb_it01.failed() ); costreambuf_iter ostrb_it02(0); @@ -53,11 +53,11 @@ void test02(void) ostrb_it02++; ++ostrb_it02; VERIFY( ostrb_it02.failed() ); - *ostrb_it02; + (void) *ostrb_it02; VERIFY( ostrb_it02.failed() ); ostrb_it02 = 'a'; VERIFY( ostrb_it02.failed() ); - + // charT operator*() const // ostreambuf_iterator& operator++(); // ostreambuf_iterator& operator++(int); diff --git a/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc b/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc index b0b379c6ea5..e679f24e75b 100644 --- a/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc +++ b/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc @@ -25,8 +25,8 @@ void test01() { int arr[3] = {1, 2, 3}; - std::begin(arr); - std::end(arr); + (void) std::begin(arr); + (void) std::end(arr); static_assert( noexcept(std::begin(arr)), "LWG 2280" ); static_assert( noexcept(std::end(arr)), "LWG 2280" ); diff --git a/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc b/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc index bbcfcece5ff..d4deedd82f6 100644 --- a/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc +++ b/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc @@ -114,15 +114,15 @@ test01() // deleted overloads in namespace ns3 (because it is an associated namespace // and those functions are exact matches for the arguments). using namespace std::ranges; - advance(iter, 1); - advance(iter, 3, sentinel); - distance(iter, sentinel); - distance(range); - next(iter); - next(iter, -1); - next(iter, sentinel); - next(iter, 5, sentinel); - prev(iter); - prev(iter, 0); - prev(iter, 0, sentinel); + (void) advance(iter, 1); + (void) advance(iter, 3, sentinel); + (void) distance(iter, sentinel); + (void) distance(range); + (void) next(iter); + (void) next(iter, -1); + (void) next(iter, sentinel); + (void) next(iter, 5, sentinel); + (void) prev(iter); + (void) prev(iter, 0); + (void) prev(iter, 0, sentinel); } diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc index 633c1426b96..bd8b20d877d 100644 --- a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc @@ -17,6 +17,8 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. +// { dg-options "-Wno-unused-result" } + // 24.4.1.2 Reverse iterators #include <iterator> diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc index 012f0082751..e5e6dd25027 100644 --- a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc @@ -1,4 +1,6 @@ // { dg-do compile } +// { dg-options "-Wno-unused-result" } + // Copyright (C) 2010-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc b/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc index a7ce1332117..cf5418a61d1 100644 --- a/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc +++ b/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc @@ -27,9 +27,9 @@ void test01() { std::valarray<double> va{1.0, 2.0, 3.0}; - std::cbegin(va); - std::cend(va); + (void) std::cbegin(va); + (void) std::cend(va); const auto& cva = va; - std::cbegin(cva); - std::cend(cva); + (void) std::cbegin(cva); + (void) std::cend(cva); } diff --git a/libstdc++-v3/testsuite/28_regex/range_access.cc b/libstdc++-v3/testsuite/28_regex/range_access.cc index 46ef3c64391..6baefbfb673 100644 --- a/libstdc++-v3/testsuite/28_regex/range_access.cc +++ b/libstdc++-v3/testsuite/28_regex/range_access.cc @@ -26,6 +26,6 @@ void test01() { std::smatch sm; - std::begin(sm); - std::end(sm); + (void) std::begin(sm); + (void) std::end(sm); } diff --git a/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc b/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc index c750430d6af..1c456920e5b 100644 --- a/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc +++ b/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc @@ -25,6 +25,6 @@ void test01() { std::experimental::string_view s("Hello, World!"); - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); } diff --git a/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc index 1dd926333c3..f19e455a606 100644 --- a/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc @@ -26,7 +26,7 @@ test01() { #ifdef _GLIBCXX_USE_WCHAR_T std::experimental::wstring_view ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); + (void) std::begin(ws); + (void) std::end(ws); #endif } diff --git a/libstdc++-v3/testsuite/ext/vstring/range_access.cc b/libstdc++-v3/testsuite/ext/vstring/range_access.cc index 8219eeabed1..7b381ffd956 100644 --- a/libstdc++-v3/testsuite/ext/vstring/range_access.cc +++ b/libstdc++-v3/testsuite/ext/vstring/range_access.cc @@ -25,12 +25,12 @@ void test01() { __gnu_cxx::__vstring s("Hello, World!"); - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); #ifdef _GLIBCXX_USE_WCHAR_T __gnu_cxx::__wvstring ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); + (void) std::begin(ws); + (void) std::end(ws); #endif } diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc index 55f74824737..d79d451478d 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc @@ -62,7 +62,7 @@ test03() int x[] = {0,1,2,3,4,5}; auto is_odd = [] (int i) { return i%2 == 1; }; auto v = x | views::filter(is_odd) | views::take(3); - ranges::begin(v); + (void) ranges::begin(v); using R = decltype(v); static_assert(ranges::view<R>); static_assert(!ranges::sized_range<R>); diff --git a/libstdc++-v3/testsuite/std/ranges/p2259.cc b/libstdc++-v3/testsuite/std/ranges/p2259.cc index 0ec7e21f657..89234e246a0 100644 --- a/libstdc++-v3/testsuite/std/ranges/p2259.cc +++ b/libstdc++-v3/testsuite/std/ranges/p2259.cc @@ -64,7 +64,7 @@ test01() // Verify the changes to common_iterator. only_cxx20_input_range auto v6 = v0 | views::common; - *(v6.begin()++); + (void) *(v6.begin()++); // Verify the changes to iota_view. only_cxx20_input_range auto v8 = ranges::iota_view{v0.begin()}; @@ -77,7 +77,7 @@ test01() static_assert(std::contiguous_iterator<decltype(i10)>); static_assert(std::same_as<std::iterator_traits<decltype(i10)>::iterator_category, std::random_access_iterator_tag>); - i10.operator->(); + (void) i10.operator->(); __iter_without_category auto i11 = std::counted_iterator{v0.begin(), 5}; } ^ permalink raw reply [flat|nested] 12+ messages in thread
* [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 11:55 [committed 1/2] libstdc++: Add [[nodiscard]] to iterators and related utilities Jonathan Wakely @ 2021-08-04 11:56 ` Jonathan Wakely 2021-08-04 12:00 ` Jonathan Wakely 2021-08-05 14:19 ` [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] Jonathan Wakely 1 sibling, 1 reply; 12+ messages in thread From: Jonathan Wakely @ 2021-08-04 11:56 UTC (permalink / raw) To: libstdc++, gcc-patches [-- Attachment #1: Type: text/plain, Size: 272 bytes --] ... and container adaptors. This adds the [[nodiscard]] attribute to functions with no side-effects for the sequence containers and their iterators, and the debug versions of those containers, and the container adaptors, Tested powerpc64le-linux, committed to trunk. [-- Attachment #2: patch.txt --] [-- Type: text/x-patch, Size: 88076 bytes --] commit 0d04fe49239d91787850036599164788f1c87785 Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Aug 3 20:50:52 2021 libstdc++: Add [[nodiscard]] to sequence containers ... and container adaptors. This adds the [[nodiscard]] attribute to functions with no side-effects for the sequence containers and their iterators, and the debug versions of those containers, and the container adaptors, Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/forward_list.h: Add [[nodiscard]] to functions with no side-effects. * include/bits/stl_bvector.h: Likewise. * include/bits/stl_deque.h: Likewise. * include/bits/stl_list.h: Likewise. * include/bits/stl_queue.h: Likewise. * include/bits/stl_stack.h: Likewise. * include/bits/stl_vector.h: Likewise. * include/debug/deque: Likewise. * include/debug/forward_list: Likewise. * include/debug/list: Likewise. * include/debug/safe_iterator.h: Likewise. * include/debug/vector: Likewise. * include/std/array: Likewise. * testsuite/23_containers/array/creation/3_neg.cc: Use -Wno-unused-result. * testsuite/23_containers/array/debug/back1_neg.cc: Cast result to void. * testsuite/23_containers/array/debug/back2_neg.cc: Likewise. * testsuite/23_containers/array/debug/front1_neg.cc: Likewise. * testsuite/23_containers/array/debug/front2_neg.cc: Likewise. * testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc: Likewise. * testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc: Likewise. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. * testsuite/23_containers/deque/cons/clear_allocator.cc: Cast result to void. * testsuite/23_containers/deque/debug/invalidation/4.cc: Likewise. * testsuite/23_containers/deque/types/1.cc: Use -Wno-unused-result. * testsuite/23_containers/list/types/1.cc: Cast result to void. * testsuite/23_containers/priority_queue/members/7161.cc: Likewise. * testsuite/23_containers/queue/members/7157.cc: Likewise. * testsuite/23_containers/vector/59829.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/types/1.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/types/2.cc: Likewise. * testsuite/23_containers/vector/types/1.cc: Use -Wno-unused-result. diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index e61746848f6..ab6d9389194 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -150,10 +150,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Fwd_list_iterator(_Fwd_list_node_base* __n) noexcept : _M_node(__n) { } + [[__nodiscard__]] reference operator*() const noexcept { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); } + [[__nodiscard__]] pointer operator->() const noexcept { return static_cast<_Node*>(this->_M_node)->_M_valptr(); } @@ -176,6 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list iterator equality comparison. */ + [[__nodiscard__]] friend bool operator==(const _Self& __x, const _Self& __y) noexcept { return __x._M_node == __y._M_node; } @@ -184,6 +187,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list iterator inequality comparison. */ + [[__nodiscard__]] friend bool operator!=(const _Self& __x, const _Self& __y) noexcept { return __x._M_node != __y._M_node; } @@ -229,10 +233,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Fwd_list_const_iterator(const iterator& __iter) noexcept : _M_node(__iter._M_node) { } + [[__nodiscard__]] reference operator*() const noexcept { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); } + [[__nodiscard__]] pointer operator->() const noexcept { return static_cast<_Node*>(this->_M_node)->_M_valptr(); } @@ -255,6 +261,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list const_iterator equality comparison. */ + [[__nodiscard__]] friend bool operator==(const _Self& __x, const _Self& __y) noexcept { return __x._M_node == __y._M_node; } @@ -263,6 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list const_iterator inequality comparison. */ + [[__nodiscard__]] friend bool operator!=(const _Self& __x, const _Self& __y) noexcept { return __x._M_node != __y._M_node; } @@ -698,6 +706,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write iterator that points before the first element * in the %forward_list. Iteration is done in ordinary element order. */ + [[__nodiscard__]] iterator before_begin() noexcept { return iterator(&this->_M_impl._M_head); } @@ -707,6 +716,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator before_begin() const noexcept { return const_iterator(&this->_M_impl._M_head); } @@ -715,6 +725,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write iterator that points to the first element * in the %forward_list. Iteration is done in ordinary element order. */ + [[__nodiscard__]] iterator begin() noexcept { return iterator(this->_M_impl._M_head._M_next); } @@ -724,6 +735,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator begin() const noexcept { return const_iterator(this->_M_impl._M_head._M_next); } @@ -733,6 +745,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] iterator end() noexcept { return iterator(nullptr); } @@ -742,6 +755,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator end() const noexcept { return const_iterator(nullptr); } @@ -751,6 +765,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_head._M_next); } @@ -760,6 +775,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbefore_begin() const noexcept { return const_iterator(&this->_M_impl._M_head); } @@ -769,6 +785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %forward_list. Iteration is done in * ordinary element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(nullptr); } @@ -777,13 +794,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns true if the %forward_list is empty. (Thus begin() would * equal end().) */ - _GLIBCXX_NODISCARD bool + [[__nodiscard__]] + bool empty() const noexcept { return this->_M_impl._M_head._M_next == nullptr; } /** * Returns the largest possible number of elements of %forward_list. */ + [[__nodiscard__]] size_type max_size() const noexcept { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); } @@ -794,6 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the first * element of the %forward_list. */ + [[__nodiscard__]] reference front() { @@ -805,6 +825,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the first * element of the %forward_list. */ + [[__nodiscard__]] const_reference front() const { @@ -1425,6 +1446,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * if corresponding elements compare equal. */ template<typename _Tp, typename _Alloc> + [[__nodiscard__]] bool operator==(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly); @@ -1442,6 +1464,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * `<` and `>=` etc. */ template<typename _Tp, typename _Alloc> + [[nodiscard]] inline __detail::__synth3way_t<_Tp> operator<=>(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) @@ -1464,6 +1487,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * See std::lexicographical_compare() for how the determination is made. */ template<typename _Tp, typename _Alloc> + [[__nodiscard__]] inline bool operator<(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1472,6 +1496,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator== template<typename _Tp, typename _Alloc> + [[__nodiscard__]] inline bool operator!=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1479,6 +1504,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator< template<typename _Tp, typename _Alloc> + [[__nodiscard__]] inline bool operator>(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1486,6 +1512,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator< template<typename _Tp, typename _Alloc> + [[__nodiscard__]] inline bool operator>=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1493,6 +1520,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator< template<typename _Tp, typename _Alloc> + [[__nodiscard__]] inline bool operator<=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index fadb6615102..a954890ff20 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -83,6 +83,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Bit_reference(const _Bit_reference&) = default; #endif + _GLIBCXX_NODISCARD operator bool() const _GLIBCXX_NOEXCEPT { return !!(*_M_p & _M_mask); } @@ -100,10 +101,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER operator=(const _Bit_reference& __x) _GLIBCXX_NOEXCEPT { return *this = bool(__x); } + _GLIBCXX_NODISCARD bool operator==(const _Bit_reference& __x) const { return bool(*this) == bool(__x); } + _GLIBCXX_NODISCARD bool operator<(const _Bit_reference& __x) const { return !bool(*this) && bool(__x); } @@ -182,11 +185,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_offset = static_cast<unsigned int>(__n); } + _GLIBCXX_NODISCARD friend _GLIBCXX20_CONSTEXPR bool operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return __x._M_p == __y._M_p && __x._M_offset == __y._M_offset; } #if __cpp_lib_three_way_comparison + [[nodiscard]] friend constexpr strong_ordering operator<=>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) noexcept @@ -196,6 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __x._M_offset <=> __y._M_offset; } #else + _GLIBCXX_NODISCARD friend bool operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { @@ -203,18 +209,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset); } + _GLIBCXX_NODISCARD friend bool operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return !(__x == __y); } + _GLIBCXX_NODISCARD friend bool operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return __y < __x; } + _GLIBCXX_NODISCARD friend bool operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return !(__y < __x); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return !(__x < __y); } @@ -247,6 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_const_cast() const { return *this; } + _GLIBCXX_NODISCARD reference operator*() const { return reference(_M_p, 1UL << _M_offset); } @@ -295,10 +306,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return *this; } + _GLIBCXX_NODISCARD reference operator[](difference_type __i) const { return *(*this + __i); } + _GLIBCXX_NODISCARD friend iterator operator+(const iterator& __x, difference_type __n) { @@ -307,10 +320,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend iterator operator+(difference_type __n, const iterator& __x) { return __x + __n; } + _GLIBCXX_NODISCARD friend iterator operator-(const iterator& __x, difference_type __n) { @@ -343,6 +358,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_const_cast() const { return _Bit_iterator(_M_p, _M_offset); } + _GLIBCXX_NODISCARD const_reference operator*() const { return _Bit_reference(_M_p, 1UL << _M_offset); } @@ -391,10 +407,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return *this; } + _GLIBCXX_NODISCARD const_reference operator[](difference_type __i) const { return *(*this + __i); } + _GLIBCXX_NODISCARD friend const_iterator operator+(const const_iterator& __x, difference_type __n) { @@ -403,6 +421,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend const_iterator operator-(const const_iterator& __x, difference_type __n) { @@ -411,6 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend const_iterator operator+(difference_type __n, const const_iterator& __x) { return __x + __n; } @@ -827,60 +847,74 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); } #endif + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_start._M_p, 0); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_start._M_p, 0); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_start._M_p, 0); } + [[__nodiscard__]] const_iterator cend() const noexcept { return this->_M_impl._M_finish; } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } #endif + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return size_type(end() - begin()); } + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { @@ -893,6 +927,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ? __asize * int(_S_word_bit) : __isize); } + _GLIBCXX_NODISCARD size_type capacity() const _GLIBCXX_NOEXCEPT { return size_type(const_iterator(this->_M_impl._M_end_addr(), 0) @@ -902,10 +937,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER empty() const _GLIBCXX_NOEXCEPT { return begin() == end(); } + _GLIBCXX_NODISCARD reference operator[](size_type __n) { return begin()[__n]; } + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const { return begin()[__n]; } @@ -939,18 +976,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_reallocate(__n); } + _GLIBCXX_NODISCARD reference front() { return *begin(); } + _GLIBCXX_NODISCARD const_reference front() const { return *begin(); } + _GLIBCXX_NODISCARD reference back() { return *(end() - 1); } + _GLIBCXX_NODISCARD const_reference back() const { return *(end() - 1); } diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 20c73b4fc3c..6095498d440 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -176,10 +176,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_const_cast() const _GLIBCXX_NOEXCEPT { return iterator(_M_cur, _M_node); } + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { return *_M_cur; } + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { return _M_cur; } @@ -247,6 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER operator-=(difference_type __n) _GLIBCXX_NOEXCEPT { return *this += -__n; } + _GLIBCXX_NODISCARD reference operator[](difference_type __n) const _GLIBCXX_NOEXCEPT { return *(*this + __n); } @@ -264,6 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_last = _M_first + difference_type(_S_buffer_size()); } + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_cur == __y._M_cur; } @@ -272,6 +276,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // order to avoid ambiguous overload resolution when std::rel_ops // operators are in scope (for additional details, see libstdc++/3628) template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) @@ -279,6 +284,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return __x._M_cur == __y._M_cur; } #if __cpp_lib_three_way_comparison + [[nodiscard]] friend strong_ordering operator<=>(const _Self& __x, const _Self& __y) noexcept { @@ -287,17 +293,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __x._M_cur <=> __y._M_cur; } #else + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return !(__x == __y); } template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT { return !(__x == __y); } + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { @@ -306,6 +315,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) @@ -315,33 +325,39 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); } + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __y < __x; } template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT { return __y < __x; } + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return !(__y < __x); } template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT { return !(__y < __x); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return !(__x < __y); } template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) @@ -349,6 +365,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return !(__x < __y); } #endif // three-way comparison + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { @@ -363,6 +380,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // operators but also operator- must accept mixed iterator/const_iterator // parameters. template<typename _RefR, typename _PtrR> + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT @@ -373,6 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + (__y._M_last - __y._M_cur); } + _GLIBCXX_NODISCARD friend _Self operator+(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { @@ -381,6 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend _Self operator-(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { @@ -389,6 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend _Self operator+(difference_type __n, const _Self& __x) _GLIBCXX_NOEXCEPT { return __x + __n; } @@ -1114,6 +1135,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif /// Get a copy of the memory allocation object. + _GLIBCXX_NODISCARD allocator_type get_allocator() const _GLIBCXX_NOEXCEPT { return _Base::get_allocator(); } @@ -1123,6 +1145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write iterator that points to the first element in the * %deque. Iteration is done in ordinary element order. */ + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_start; } @@ -1131,6 +1154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) iterator that points to the first * element in the %deque. Iteration is done in ordinary element order. */ + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_start; } @@ -1140,6 +1164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %deque. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } @@ -1149,6 +1174,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %deque. Iteration is done in * ordinary element order. */ + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } @@ -1158,6 +1184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * last element in the %deque. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(this->_M_impl._M_finish); } @@ -1167,6 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %deque. Iteration is done in * reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(this->_M_impl._M_finish); } @@ -1176,6 +1204,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * before the first element in the %deque. Iteration is done * in reverse element order. */ + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(this->_M_impl._M_start); } @@ -1185,6 +1214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %deque. Iteration is * done in reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(this->_M_impl._M_start); } @@ -1194,6 +1224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) iterator that points to the first * element in the %deque. Iteration is done in ordinary element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return this->_M_impl._M_start; } @@ -1203,6 +1234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %deque. Iteration is done in * ordinary element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return this->_M_impl._M_finish; } @@ -1212,6 +1244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %deque. Iteration is done in * reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(this->_M_impl._M_finish); } @@ -1221,6 +1254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %deque. Iteration is * done in reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(this->_M_impl._M_start); } @@ -1228,11 +1262,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // [23.2.1.2] capacity /** Returns the number of elements in the %deque. */ + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish - this->_M_impl._M_start; } /** Returns the size() of the largest possible %deque. */ + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { return _S_max_size(_M_get_Tp_allocator()); } @@ -1322,6 +1358,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -1340,6 +1377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -1400,6 +1438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the first * element of the %deque. */ + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -1411,6 +1450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the first * element of the %deque. */ + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -1422,6 +1462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the last element of the * %deque. */ + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -1435,6 +1476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the last * element of the %deque. */ + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { @@ -2242,6 +2284,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * and if corresponding elements compare equal. */ template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator==(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return __x.size() == __y.size() @@ -2260,6 +2303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * `<` and `>=` etc. */ template<typename _Tp, typename _Alloc> + [[nodiscard]] inline __detail::__synth3way_t<_Tp> operator<=>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { @@ -2280,6 +2324,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * See std::lexicographical_compare() for how the determination is made. */ template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), @@ -2287,24 +2332,28 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator== template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator!=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__x < __y); } diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index dbe05a9834b..9ae640ee692 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -205,10 +205,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return *this; } // Must downcast from _List_node_base to _List_node to get to value. + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { return *static_cast<_Node*>(_M_node)->_M_valptr(); } + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { return static_cast<_Node*>(_M_node)->_M_valptr(); } @@ -243,11 +245,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node == __y._M_node; } #if __cpp_impl_three_way_comparison < 201907L + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node != __y._M_node; } @@ -291,10 +295,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return iterator(const_cast<__detail::_List_node_base*>(_M_node)); } // Must downcast from List_node_base to _List_node to get to value. + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { return *static_cast<_Node*>(_M_node)->_M_valptr(); } + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { return static_cast<_Node*>(_M_node)->_M_valptr(); } @@ -329,11 +335,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node == __y._M_node; } #if __cpp_impl_three_way_comparison < 201907L + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node != __y._M_node; } @@ -941,6 +949,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write iterator that points to the first element in the * %list. Iteration is done in ordinary element order. */ + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_node._M_next); } @@ -950,6 +959,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first element in the %list. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_node._M_next); } @@ -959,6 +969,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * element in the %list. Iteration is done in ordinary element * order. */ + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(&this->_M_impl._M_node); } @@ -968,6 +979,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(&this->_M_impl._M_node); } @@ -977,6 +989,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * element in the %list. Iteration is done in reverse element * order. */ + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } @@ -986,6 +999,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } @@ -995,6 +1009,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * before the first element in the %list. Iteration is done in * reverse element order. */ + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } @@ -1004,6 +1019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * before the first element in the %list. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } @@ -1014,6 +1030,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first element in the %list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_node._M_next); } @@ -1023,6 +1040,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(&this->_M_impl._M_node); } @@ -1032,6 +1050,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in reverse * element order. */ + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } @@ -1041,6 +1060,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * before the first element in the %list. Iteration is done in reverse * element order. */ + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -1056,11 +1076,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } /** Returns the number of elements in the %list. */ + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return _M_node_count(); } /** Returns the size() of the largest possible %list. */ + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { return _Node_alloc_traits::max_size(_M_get_Node_allocator()); } @@ -1110,6 +1132,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write reference to the data at the first * element of the %list. */ + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { return *begin(); } @@ -1118,6 +1141,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) reference to the data at the first * element of the %list. */ + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { return *begin(); } @@ -1126,6 +1150,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write reference to the data at the last element * of the %list. */ + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -1138,6 +1163,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) reference to the data at the last * element of the %list. */ + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { @@ -1991,6 +2017,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * equal, and if corresponding elements compare equal. */ template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { @@ -2026,6 +2053,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * `<` and `>=` etc. */ template<typename _Tp, typename _Alloc> + [[nodiscard]] inline __detail::__synth3way_t<_Tp> operator<=>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { @@ -2046,6 +2074,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * See std::lexicographical_compare() for how the determination is made. */ template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), @@ -2053,24 +2082,28 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// Based on operator== template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x < __y); } diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index 936cf0d2380..363868fe0a6 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -107,15 +107,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template<typename _Tp1, typename _Seq1> + _GLIBCXX_NODISCARD friend bool operator==(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); template<typename _Tp1, typename _Seq1> + _GLIBCXX_NODISCARD friend bool operator<(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); #if __cpp_lib_three_way_comparison template<typename _Tp1, three_way_comparable _Seq1> + [[nodiscard]] friend compare_three_way_result_t<_Seq1> operator<=>(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); #endif @@ -204,6 +207,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return c.empty(); } /** Returns the number of elements in the %queue. */ + _GLIBCXX_NODISCARD size_type size() const { return c.size(); } @@ -212,6 +216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read/write reference to the data at the first * element of the %queue. */ + _GLIBCXX_NODISCARD reference front() { @@ -223,6 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the first * element of the %queue. */ + _GLIBCXX_NODISCARD const_reference front() const { @@ -234,6 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read/write reference to the data at the last * element of the %queue. */ + _GLIBCXX_NODISCARD reference back() { @@ -245,6 +252,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the last * element of the %queue. */ + _GLIBCXX_NODISCARD const_reference back() const { @@ -340,6 +348,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * if their sequences compare equal. */ template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator==(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c == __y.c; } @@ -358,36 +367,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * determination. */ template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c < __y.c; } /// Based on operator== template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator!=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator>(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __y < __x; } /// Based on operator< template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator<=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator>=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__x < __y); } #if __cpp_lib_three_way_comparison template<typename _Tp, three_way_comparable _Seq> + [[nodiscard]] inline compare_three_way_result_t<_Seq> operator<=>(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c <=> __y.c; } @@ -613,6 +628,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return c.empty(); } /** Returns the number of elements in the %queue. */ + _GLIBCXX_NODISCARD size_type size() const { return c.size(); } @@ -621,6 +637,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the first * element of the %queue. */ + _GLIBCXX_NODISCARD const_reference top() const { diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h index 2a460d2751a..85137b9d428 100644 --- a/libstdc++-v3/include/bits/stl_stack.h +++ b/libstdc++-v3/include/bits/stl_stack.h @@ -200,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return c.empty(); } /** Returns the number of elements in the %stack. */ + _GLIBCXX_NODISCARD size_type size() const { return c.size(); } @@ -208,6 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read/write reference to the data at the first * element of the %stack. */ + _GLIBCXX_NODISCARD reference top() { @@ -219,6 +221,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the first * element of the %stack. */ + _GLIBCXX_NODISCARD const_reference top() const { @@ -315,6 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * equal. */ template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator==(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __x.c == __y.c; } @@ -333,36 +337,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * determination. */ template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator<(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __x.c < __y.c; } /// Based on operator== template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator!=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator>(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __y < __x; } /// Based on operator< template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator<=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Seq> + _GLIBCXX_NODISCARD inline bool operator>=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__x < __y); } #if __cpp_lib_three_way_comparison template<typename _Tp, three_way_comparable _Seq> + [[nodiscard]] inline compare_three_way_result_t<_Seq> operator<=>(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __x.c <=> __y.c; } diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 06abf01ab0e..296da43822a 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -807,6 +807,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %vector. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_start); } @@ -816,6 +817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %vector. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_start); } @@ -825,6 +827,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %vector. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_finish); } @@ -834,6 +837,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %vector. Iteration is done in * ordinary element order. */ + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_finish); } @@ -843,6 +847,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * last element in the %vector. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } @@ -852,6 +857,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %vector. Iteration is done in * reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } @@ -861,6 +867,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * before the first element in the %vector. Iteration is done * in reverse element order. */ + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } @@ -870,6 +877,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %vector. Iteration * is done in reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } @@ -880,6 +888,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %vector. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_start); } @@ -889,6 +898,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %vector. Iteration is done in * ordinary element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(this->_M_impl._M_finish); } @@ -898,6 +908,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %vector. Iteration is done in * reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } @@ -907,6 +918,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %vector. Iteration * is done in reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -914,11 +926,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // [23.2.4.2] capacity /** Returns the number of elements in the %vector. */ + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); } /** Returns the size() of the largest possible %vector. */ + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { return _S_max_size(_M_get_Tp_allocator()); } @@ -994,6 +1008,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns the total number of elements that the %vector can * hold before needing to allocate more memory. */ + _GLIBCXX_NODISCARD size_type capacity() const _GLIBCXX_NOEXCEPT { return size_type(this->_M_impl._M_end_of_storage @@ -1039,6 +1054,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -1057,6 +1073,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -1117,6 +1134,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the first * element of the %vector. */ + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -1128,6 +1146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the first * element of the %vector. */ + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -1139,6 +1158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the last * element of the %vector. */ + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -1150,6 +1170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the * last element of the %vector. */ + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { @@ -1164,10 +1185,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a pointer such that [data(), data() + size()) is a valid * range. For a non-empty %vector, data() == &front(). */ + _GLIBCXX_NODISCARD _Tp* data() _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } + _GLIBCXX_NODISCARD const _Tp* data() const _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 227d083da04..4257a1651bd 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -219,51 +219,63 @@ namespace __debug using _Base::get_allocator; // iterators: + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(_Base::begin(), this); } + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(_Base::end(), this); } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -335,6 +347,7 @@ namespace __debug using _Base::empty; // element access: + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -342,6 +355,7 @@ namespace __debug return _M_base()[__n]; } + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -351,6 +365,7 @@ namespace __debug using _Base::at; + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -358,6 +373,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -365,6 +381,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -372,6 +389,7 @@ namespace __debug return _Base::back(); } + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list index 16f0531dce7..9cc05e8129c 100644 --- a/libstdc++-v3/include/debug/forward_list +++ b/libstdc++-v3/include/debug/forward_list @@ -327,38 +327,47 @@ namespace __debug // iterators: + [[__nodiscard__]] iterator before_begin() noexcept { return { _Base::before_begin(), this }; } + [[__nodiscard__]] const_iterator before_begin() const noexcept { return { _Base::before_begin(), this }; } + [[__nodiscard__]] iterator begin() noexcept { return { _Base::begin(), this }; } + [[__nodiscard__]] const_iterator begin() const noexcept { return { _Base::begin(), this }; } + [[__nodiscard__]] iterator end() noexcept { return { _Base::end(), this }; } + [[__nodiscard__]] const_iterator end() const noexcept { return { _Base::end(), this }; } + [[__nodiscard__]] const_iterator cbegin() const noexcept { return { _Base::cbegin(), this }; } + [[__nodiscard__]] const_iterator cbefore_begin() const noexcept { return { _Base::cbefore_begin(), this }; } + [[__nodiscard__]] const_iterator cend() const noexcept { return { _Base::cend(), this }; } @@ -368,6 +377,7 @@ namespace __debug // element access: + [[__nodiscard__]] reference front() { @@ -375,6 +385,7 @@ namespace __debug return _Base::front(); } + [[__nodiscard__]] const_reference front() const { diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 01fe43fc7df..83122f8248d 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -223,51 +223,63 @@ namespace __debug using _Base::get_allocator; // iterators: + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(_Base::begin(), this); } + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(_Base::end(), this); } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -356,6 +368,7 @@ namespace __debug #endif // element access: + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -363,6 +376,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -370,6 +384,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -377,6 +392,7 @@ namespace __debug return _Base::back(); } + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index 8e138fd32e5..5584d06de5a 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -297,6 +297,7 @@ namespace __gnu_debug * @brief Iterator dereference. * @pre iterator is dereferenceable */ + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { @@ -310,6 +311,7 @@ namespace __gnu_debug * @brief Iterator dereference. * @pre iterator is dereferenceable */ + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { @@ -463,6 +465,7 @@ namespace __gnu_debug typedef _Safe_iterator<_Iterator, _Sequence, iterator_category> _Self; + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -471,6 +474,7 @@ namespace __gnu_debug } template<typename _IteR> + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __lhs, const _Safe_iterator<_IteR, _Sequence, iterator_category>& __rhs) @@ -481,6 +485,7 @@ namespace __gnu_debug } #if ! __cpp_lib_three_way_comparison + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -489,6 +494,7 @@ namespace __gnu_debug } template<typename _IteR> + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __lhs, const _Safe_iterator<_IteR, _Sequence, iterator_category>& __rhs) @@ -786,6 +792,7 @@ namespace __gnu_debug } // ------ Random access iterator requirements ------ + _GLIBCXX_NODISCARD reference operator[](difference_type __n) const _GLIBCXX_NOEXCEPT { @@ -819,6 +826,7 @@ namespace __gnu_debug } #if __cpp_lib_three_way_comparison + [[nodiscard]] friend auto operator<=>(const _Self& __lhs, const _Self& __rhs) noexcept { @@ -826,6 +834,7 @@ namespace __gnu_debug return __lhs.base() <=> __rhs.base(); } + [[nodiscard]] friend auto operator<=>(const _Self& __lhs, const _OtherSelf& __rhs) noexcept { @@ -833,6 +842,7 @@ namespace __gnu_debug return __lhs.base() <=> __rhs.base(); } #else + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -840,6 +850,7 @@ namespace __gnu_debug return __lhs.base() < __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -847,6 +858,7 @@ namespace __gnu_debug return __lhs.base() < __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -854,6 +866,7 @@ namespace __gnu_debug return __lhs.base() <= __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -861,6 +874,7 @@ namespace __gnu_debug return __lhs.base() <= __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -868,6 +882,7 @@ namespace __gnu_debug return __lhs.base() > __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -875,6 +890,7 @@ namespace __gnu_debug return __lhs.base() > __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -882,6 +898,7 @@ namespace __gnu_debug return __lhs.base() >= __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -894,6 +911,7 @@ namespace __gnu_debug // According to the resolution of DR179 not only the various comparison // operators but also operator- must accept mixed iterator/const_iterator // parameters. + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -901,6 +919,7 @@ namespace __gnu_debug return __lhs.base() - __rhs.base(); } + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -908,6 +927,7 @@ namespace __gnu_debug return __lhs.base() - __rhs.base(); } + _GLIBCXX_NODISCARD friend _Self operator+(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { @@ -917,6 +937,7 @@ namespace __gnu_debug return _Safe_iterator(__x.base() + __n, __x._M_sequence); } + _GLIBCXX_NODISCARD friend _Self operator+(difference_type __n, const _Self& __x) _GLIBCXX_NOEXCEPT { @@ -926,6 +947,7 @@ namespace __gnu_debug return _Safe_iterator(__n + __x.base(), __x._M_sequence); } + _GLIBCXX_NODISCARD friend _Self operator-(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 79ccf527dd6..55271384922 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -303,51 +303,63 @@ namespace __debug using _Base::get_allocator; // iterators: + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(_Base::begin(), this); } + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(_Base::end(), this); } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -407,6 +419,7 @@ namespace __debug } #endif + _GLIBCXX_NODISCARD size_type capacity() const _GLIBCXX_NOEXCEPT { @@ -431,6 +444,7 @@ namespace __debug } // element access: + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -438,6 +452,7 @@ namespace __debug return _M_base()[__n]; } + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -447,6 +462,7 @@ namespace __debug using _Base::at; + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -454,6 +470,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -461,6 +478,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -468,6 +486,7 @@ namespace __debug return _Base::back(); } + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index ea8d3cb5f2e..3e12d35157c 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -127,65 +127,81 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::swap_ranges(begin(), end(), __other.begin()); } // Iterators. + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR iterator begin() noexcept { return iterator(data()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator begin() const noexcept { return const_iterator(data()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR iterator end() noexcept { return iterator(data() + _Nm); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator end() const noexcept { return const_iterator(data() + _Nm); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reverse_iterator rend() noexcept { return reverse_iterator(begin()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator cbegin() const noexcept { return const_iterator(data()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator cend() const noexcept { return const_iterator(data() + _Nm); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } // Capacity. + [[__nodiscard__]] constexpr size_type size() const noexcept { return _Nm; } + [[__nodiscard__]] constexpr size_type max_size() const noexcept { return _Nm; } - _GLIBCXX_NODISCARD constexpr bool + [[__nodiscard__]] + constexpr bool empty() const noexcept { return size() == 0; } // Element access. + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference operator[](size_type __n) noexcept { @@ -193,6 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _AT_Type::_S_ref(_M_elems, __n); } + [[__nodiscard__]] constexpr const_reference operator[](size_type __n) const noexcept { @@ -224,6 +241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _AT_Type::_S_ref(_M_elems, 0)); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference front() noexcept { @@ -231,6 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *begin(); } + [[__nodiscard__]] constexpr const_reference front() const noexcept { @@ -240,6 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _AT_Type::_S_ref(_M_elems, 0); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference back() noexcept { @@ -247,6 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Nm ? *(end() - 1) : *end(); } + [[__nodiscard__]] constexpr const_reference back() const noexcept { @@ -257,10 +278,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _AT_Type::_S_ref(_M_elems, 0); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR pointer data() noexcept { return _AT_Type::_S_ptr(_M_elems); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_pointer data() const noexcept { return _AT_Type::_S_ptr(_M_elems); } @@ -275,6 +298,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Array comparisons. template<typename _Tp, std::size_t _Nm> + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) @@ -282,6 +306,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_three_way_comparison && __cpp_lib_concepts template<typename _Tp, size_t _Nm> + [[nodiscard]] constexpr __detail::__synth3way_t<_Tp> operator<=>(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) { @@ -304,12 +329,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #else template<typename _Tp, std::size_t _Nm> + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one == __two); } template<typename _Tp, std::size_t _Nm> + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) @@ -319,18 +346,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, std::size_t _Nm> + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return __two < __one; } template<typename _Tp, std::size_t _Nm> + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one > __two); } template<typename _Tp, std::size_t _Nm> + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) @@ -361,6 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template<std::size_t _Int, typename _Tp, std::size_t _Nm> + [[__nodiscard__]] constexpr _Tp& get(array<_Tp, _Nm>& __arr) noexcept { @@ -369,6 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<std::size_t _Int, typename _Tp, std::size_t _Nm> + [[__nodiscard__]] constexpr _Tp&& get(array<_Tp, _Nm>&& __arr) noexcept { @@ -377,6 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<std::size_t _Int, typename _Tp, std::size_t _Nm> + [[__nodiscard__]] constexpr const _Tp& get(const array<_Tp, _Nm>& __arr) noexcept { @@ -385,6 +418,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<std::size_t _Int, typename _Tp, std::size_t _Nm> + [[__nodiscard__]] constexpr const _Tp&& get(const array<_Tp, _Nm>&& __arr) noexcept { @@ -406,6 +440,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, size_t _Nm> + [[nodiscard]] constexpr array<remove_cv_t<_Tp>, _Nm> to_array(_Tp (&__a)[_Nm]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) @@ -418,6 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, size_t _Nm> + [[nodiscard]] constexpr array<remove_cv_t<_Tp>, _Nm> to_array(_Tp (&&__a)[_Nm]) noexcept(is_nothrow_move_constructible_v<_Tp>) diff --git a/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc b/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc index c286b35fd61..e3cb6990f59 100644 --- a/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++2a" } +// { dg-options "-std=gnu++2a -Wno-unused-result" } // { dg-do compile { target c++2a } } // Copyright (C) 2019-2021 Free Software Foundation, Inc. diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc index d384b7b2ff4..01c7c45784e 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc @@ -23,7 +23,7 @@ void test01() { std::array<int, 0> a; - a.back(); + (void) a.back(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc index b27f5f0bb03..db195e86411 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc @@ -23,7 +23,7 @@ void test01() { constexpr std::array<int, 0> a; - a.back(); + (void) a.back(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc index e0d86f1c07f..700f8524950 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc @@ -23,7 +23,7 @@ void test01() { std::array<int, 0> a; - a.front(); + (void) a.front(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc index dcbe5b6dd2e..d84b301fbf8 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc @@ -23,7 +23,7 @@ void test01() { constexpr std::array<int, 0> a; - a.front(); + (void) a.front(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc index 299ba85a5cf..bc5db43e123 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc @@ -23,7 +23,7 @@ void test01() { std::array<int, 0> a; - a[0]; + (void) a[0]; } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc index 36d281af105..105952f36d9 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc @@ -23,7 +23,7 @@ void test01() { constexpr std::array<int, 0> a; - a[0]; + (void) a[0]; } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc index 423594dd2b3..70742c14a7d 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc @@ -26,6 +26,6 @@ int n1 = std::get<1>(a); int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 367 } -// { dg-error "static assertion failed" "" { target *-*-* } 375 } -// { dg-error "static assertion failed" "" { target *-*-* } 383 } +// { dg-error "static assertion failed" "" { target *-*-* } 398 } +// { dg-error "static assertion failed" "" { target *-*-* } 407 } +// { dg-error "static assertion failed" "" { target *-*-* } 416 } diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc index 29fdd46115b..12063f53bb9 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc @@ -5,12 +5,12 @@ // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. - + // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - + // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. @@ -22,12 +22,12 @@ using namespace std; using __gnu_cxx::new_allocator; template<typename T> - class clear_alloc : public new_allocator<T> + class clear_alloc : public new_allocator<T> { public: template <typename T1> - struct rebind + struct rebind { typedef clear_alloc<T1> other; }; virtual void clear() throw() @@ -35,10 +35,10 @@ template<typename T> clear_alloc() throw() { } - - clear_alloc(clear_alloc const&) throw() : new_allocator<T>() + + clear_alloc(clear_alloc const&) throw() : new_allocator<T>() { } - + template<typename T1> clear_alloc(clear_alloc<T1> const&) throw() { } @@ -51,7 +51,7 @@ template<typename T> this->clear(); return new_allocator<T>::allocate(n, hint); } - + void deallocate(T *ptr, typename new_allocator<T>::size_type n) { this->clear(); @@ -64,14 +64,14 @@ template<typename Container> { Container* pic = new Container; int x = 230; - + while (x--) { pic->push_back(x); } - - pic->get_allocator(); - + + (void) pic->get_allocator(); + // The following has led to infinite recursions or cores. pic->clear(); diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc index 6ec8b620422..aa98b7f6608 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc @@ -58,7 +58,7 @@ void test04() before = v.begin(); at = before + 3; v.erase(at, v.end()); - *before; + (void) *before; // clear() before = v.begin(); diff --git a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc index a17b1d86ec9..144eb57e13a 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile } +// { dg-options "-Wno-unused-result" } #include <deque> #include <testsuite_greedy_ops.h> diff --git a/libstdc++-v3/testsuite/23_containers/list/types/1.cc b/libstdc++-v3/testsuite/23_containers/list/types/1.cc index 1e649963b84..45222b93bce 100644 --- a/libstdc++-v3/testsuite/23_containers/list/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/types/1.cc @@ -25,7 +25,7 @@ int main() std::list<greedy_ops::X> l; const std::list<greedy_ops::X> cl; - l.size(); + (void) l.size(); l.insert(l.begin(), greedy_ops::X()); l.insert(l.begin(), 1, greedy_ops::X()); l.insert(l.begin(), cl.begin(), cl.end()); diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc index 951b667c555..3ab3d337f46 100644 --- a/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc @@ -32,7 +32,7 @@ test03() for (int i = 0; i < 3; ++i) pq.push(data[i]); - pq.top(); + (void) pq.top(); for (int i = 0; i < 2; ++i) pq.pop(); diff --git a/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc b/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc index b01201a968e..e3e5dda2ef0 100644 --- a/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc +++ b/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc @@ -29,7 +29,7 @@ test01() std::queue<int> q; q.push(1); - q.front(); + (void) q.front(); q.pop(); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/59829.cc b/libstdc++-v3/testsuite/23_containers/vector/59829.cc index 16bfb6fb327..7a7f577a643 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/59829.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/59829.cc @@ -63,5 +63,5 @@ bool operator!=(Alloc<T> l, Alloc<T> r) { return false; } int main() { std::vector<int, Alloc<int>> a; - a.data(); + (void) a.data(); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc index 3d2fe29389d..7656f840448 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc @@ -46,10 +46,10 @@ int main() std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > v(5); const std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > w(1); - v[0]; - w[0]; - v.size(); - v.capacity(); + (void) v[0]; + (void) w[0]; + (void) v.size(); + (void) v.capacity(); v.resize(1); v.insert(v.begin(), N::X()); v.insert(v.begin(), 1, N::X()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc index 9e01e8f607d..7329712a2a1 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc @@ -48,10 +48,10 @@ int main() std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > v(5); const std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > w(1); - v[0]; - w[0]; - v.size(); - v.capacity(); + (void) v[0]; + (void) w[0]; + (void) v.size(); + (void) v.capacity(); v.resize(1); v.insert(v.begin(), N::X()); v.insert(v.begin(), 1, N::X()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc index 803f658eedd..7295a64a008 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile } +// { dg-options "-Wno-unused-result" } #include <vector> #include <testsuite_greedy_ops.h> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 11:56 ` [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers Jonathan Wakely @ 2021-08-04 12:00 ` Jonathan Wakely 2021-08-05 12:09 ` Christophe Lyon 2021-08-05 14:38 ` Jonathan Wakely 0 siblings, 2 replies; 12+ messages in thread From: Jonathan Wakely @ 2021-08-04 12:00 UTC (permalink / raw) To: libstdc++, gcc-patches On 04/08/21 12:56 +0100, Jonathan Wakely wrote: >... and container adaptors. > >This adds the [[nodiscard]] attribute to functions with no side-effects >for the sequence containers and their iterators, and the debug versions >of those containers, and the container adaptors, I don't plan to add any more [[nodiscard]] attributes for now, but these two commits should demonstrate how to do it for anybody who wants to contribute similar patches. I didn't add tests that verify we do actually warn on each of those functions, because there are hundreds of them, and I know they're working because I had to alter existing tests to not warn. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:00 ` Jonathan Wakely @ 2021-08-05 12:09 ` Christophe Lyon 2021-08-05 12:13 ` Ville Voutilainen 2021-08-05 14:38 ` Jonathan Wakely 1 sibling, 1 reply; 12+ messages in thread From: Christophe Lyon @ 2021-08-05 12:09 UTC (permalink / raw) To: Jonathan Wakely; +Cc: libstdc++, GCC Patches Hi Jonathan, On Wed, Aug 4, 2021 at 2:04 PM Jonathan Wakely via Gcc-patches < gcc-patches@gcc.gnu.org> wrote: > On 04/08/21 12:56 +0100, Jonathan Wakely wrote: > >... and container adaptors. > > > >This adds the [[nodiscard]] attribute to functions with no side-effects > >for the sequence containers and their iterators, and the debug versions > >of those containers, and the container adaptors, > > I don't plan to add any more [[nodiscard]] attributes for now, but > these two commits should demonstrate how to do it for anybody who > wants to contribute similar patches. > > I didn't add tests that verify we do actually warn on each of those > functions, because there are hundreds of them, and I know they're > working because I had to alter existing tests to not warn. > > I've noticed a regression on aarch64/arm: FAIL: g++.old-deja/g++.other/inline7.C -std=gnu++17 (test for excess errors) Excess errors: /gcc/testsuite/g++.old-deja/g++.other/inline7.C:11:11: warning: ignoring return value of 'std::__cxx11::list<_Tp, _Alloc>::size_type std::__cxx11::list<_Tp, _Alloc>::size() const [with _Tp = int*; _Alloc = std::allocator<int*>; std::__cxx11::list<_Tp, _Alloc>::size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] FAIL: g++.old-deja/g++.other/inline7.C -std=gnu++2a (test for excess errors) Excess errors: /gcc/testsuite/g++.old-deja/g++.other/inline7.C:11:11: warning: ignoring return value of 'std::__cxx11::list<_Tp, _Alloc>::size_type std::__cxx11::list<_Tp, _Alloc>::size() const [with _Tp = int*; _Alloc = std::allocator<int*>; std::__cxx11::list<_Tp, _Alloc>::size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] Not sure why you didn't see it? Christophe ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers 2021-08-05 12:09 ` Christophe Lyon @ 2021-08-05 12:13 ` Ville Voutilainen 2021-08-05 14:21 ` Jonathan Wakely 0 siblings, 1 reply; 12+ messages in thread From: Ville Voutilainen @ 2021-08-05 12:13 UTC (permalink / raw) To: Christophe Lyon; +Cc: Jonathan Wakely, libstdc++, GCC Patches On Thu, 5 Aug 2021 at 15:11, Christophe Lyon via Libstdc++ <libstdc++@gcc.gnu.org> wrote: > > Hi Jonathan, > > On Wed, Aug 4, 2021 at 2:04 PM Jonathan Wakely via Gcc-patches < > gcc-patches@gcc.gnu.org> wrote: > > > On 04/08/21 12:56 +0100, Jonathan Wakely wrote: > > >... and container adaptors. > > > > > >This adds the [[nodiscard]] attribute to functions with no side-effects > > >for the sequence containers and their iterators, and the debug versions > > >of those containers, and the container adaptors, > > > > I don't plan to add any more [[nodiscard]] attributes for now, but > > these two commits should demonstrate how to do it for anybody who > > wants to contribute similar patches. > > > > I didn't add tests that verify we do actually warn on each of those > > functions, because there are hundreds of them, and I know they're > > working because I had to alter existing tests to not warn. > > > > > I've noticed a regression on aarch64/arm: > FAIL: g++.old-deja/g++.other/inline7.C -std=gnu++17 (test for excess > errors) > Excess errors: > /gcc/testsuite/g++.old-deja/g++.other/inline7.C:11:11: warning: ignoring > return value of 'std::__cxx11::list<_Tp, _Alloc>::size_type > std::__cxx11::list<_Tp, _Alloc>::size() const [with _Tp = int*; _Alloc = > std::allocator<int*>; std::__cxx11::list<_Tp, _Alloc>::size_type = long > unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] > > FAIL: g++.old-deja/g++.other/inline7.C -std=gnu++2a (test for excess > errors) > Excess errors: > /gcc/testsuite/g++.old-deja/g++.other/inline7.C:11:11: warning: ignoring > return value of 'std::__cxx11::list<_Tp, _Alloc>::size_type > std::__cxx11::list<_Tp, _Alloc>::size() const [with _Tp = int*; _Alloc = > std::allocator<int*>; std::__cxx11::list<_Tp, _Alloc>::size_type = long > unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] > > Not sure why you didn't see it? That can easily happen when running just the library tests, rather than all of them. :P ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers 2021-08-05 12:13 ` Ville Voutilainen @ 2021-08-05 14:21 ` Jonathan Wakely 0 siblings, 0 replies; 12+ messages in thread From: Jonathan Wakely @ 2021-08-05 14:21 UTC (permalink / raw) To: Ville Voutilainen; +Cc: Christophe Lyon, libstdc++, GCC Patches [-- Attachment #1: Type: text/plain, Size: 2285 bytes --] On Thu, 5 Aug 2021 at 13:14, Ville Voutilainen <ville.voutilainen@gmail.com> wrote: > > On Thu, 5 Aug 2021 at 15:11, Christophe Lyon via Libstdc++ > <libstdc++@gcc.gnu.org> wrote: > > > > Hi Jonathan, > > > > On Wed, Aug 4, 2021 at 2:04 PM Jonathan Wakely via Gcc-patches < > > gcc-patches@gcc.gnu.org> wrote: > > > > > On 04/08/21 12:56 +0100, Jonathan Wakely wrote: > > > >... and container adaptors. > > > > > > > >This adds the [[nodiscard]] attribute to functions with no side-effects > > > >for the sequence containers and their iterators, and the debug versions > > > >of those containers, and the container adaptors, > > > > > > I don't plan to add any more [[nodiscard]] attributes for now, but > > > these two commits should demonstrate how to do it for anybody who > > > wants to contribute similar patches. > > > > > > I didn't add tests that verify we do actually warn on each of those > > > functions, because there are hundreds of them, and I know they're > > > working because I had to alter existing tests to not warn. > > > > > > > > I've noticed a regression on aarch64/arm: > > FAIL: g++.old-deja/g++.other/inline7.C -std=gnu++17 (test for excess > > errors) > > Excess errors: > > /gcc/testsuite/g++.old-deja/g++.other/inline7.C:11:11: warning: ignoring > > return value of 'std::__cxx11::list<_Tp, _Alloc>::size_type > > std::__cxx11::list<_Tp, _Alloc>::size() const [with _Tp = int*; _Alloc = > > std::allocator<int*>; std::__cxx11::list<_Tp, _Alloc>::size_type = long > > unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] > > > > FAIL: g++.old-deja/g++.other/inline7.C -std=gnu++2a (test for excess > > errors) > > Excess errors: > > /gcc/testsuite/g++.old-deja/g++.other/inline7.C:11:11: warning: ignoring > > return value of 'std::__cxx11::list<_Tp, _Alloc>::size_type > > std::__cxx11::list<_Tp, _Alloc>::size() const [with _Tp = int*; _Alloc = > > std::allocator<int*>; std::__cxx11::list<_Tp, _Alloc>::size_type = long > > unsigned int]', declared with attribute 'nodiscard' [-Wunused-result] > > > > Not sure why you didn't see it? > > That can easily happen when running just the library tests, rather > than all of them. :P Right, I didn't run all the compiler tests. Fixed with this patch, tested x86_64-linux, pushed to trunk. [-- Attachment #2: patch.txt --] [-- Type: text/plain, Size: 728 bytes --] commit 03d47da7e1e91adddbde261ffefd2760df59a564 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Aug 5 14:00:35 2021 testsuite: Fix warning introduced by nodiscard in libstdc++ Signed-off-by: Jonathan Wakely <jwakely@redhat.com> gcc/testsuite/ChangeLog: * g++.old-deja/g++.other/inline7.C: Cast nodiscard call to void. diff --git a/gcc/testsuite/g++.old-deja/g++.other/inline7.C b/gcc/testsuite/g++.old-deja/g++.other/inline7.C index a3723cfba1e..626000039c5 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/inline7.C +++ b/gcc/testsuite/g++.old-deja/g++.other/inline7.C @@ -8,7 +8,7 @@ std::list<int*> li; void f () { - li.size (); + (void) li.size (); } int main () ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:00 ` Jonathan Wakely 2021-08-05 12:09 ` Christophe Lyon @ 2021-08-05 14:38 ` Jonathan Wakely 1 sibling, 0 replies; 12+ messages in thread From: Jonathan Wakely @ 2021-08-05 14:38 UTC (permalink / raw) To: libstdc++, gcc-patches [-- Attachment #1: Type: text/plain, Size: 623 bytes --] On 04/08/21 13:00 +0100, Jonathan Wakely wrote: >On 04/08/21 12:56 +0100, Jonathan Wakely wrote: >>... and container adaptors. >> >>This adds the [[nodiscard]] attribute to functions with no side-effects >>for the sequence containers and their iterators, and the debug versions >>of those containers, and the container adaptors, > >I don't plan to add any more [[nodiscard]] attributes for now, but >these two commits should demonstrate how to do it for anybody who >wants to contribute similar patches. OK, one more change in this vein, adding [[nodiscard]] to <compare>. Tested powerpc64le-linux, committed to trunk. [-- Attachment #2: patch.txt --] [-- Type: text/x-patch, Size: 10719 bytes --] commit 8dec72aeb54e98643c0fb3d53768cdb96cf1342a Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Aug 5 14:01:31 2021 libstdc++: Add [[nodiscard]] to <compare> This adds the [[nodiscard]] attribute to all conversion operators, comparison operators, call operators and non-member functions in <compare>. Nothing in this header except constructors has side effects. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * libsupc++/compare (partial_ordering, weak_ordering) (strong_ordering, is_eq, is_neq, is_lt, is_lteq, is_gt, is_gteq) (compare_three_way, strong_order, weak_order, partial_order) (compare_strong_order_fallback, compare_weak_order_fallback) (compare_partial_order_fallback, __detail::__synth3way): Add nodiscard attribute. * testsuite/18_support/comparisons/categories/zero_neg.cc: Add -Wno-unused-result to options. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index dd0ec5fa36d..faeff641437 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -86,49 +86,61 @@ namespace std static const partial_ordering unordered; // comparisons + [[nodiscard]] friend constexpr bool operator==(partial_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value == 0; } + [[nodiscard]] friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default; + [[nodiscard]] friend constexpr bool operator< (partial_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value == -1; } + [[nodiscard]] friend constexpr bool operator> (partial_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value == 1; } + [[nodiscard]] friend constexpr bool operator<=(partial_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value <= 0; } + [[nodiscard]] friend constexpr bool operator>=(partial_ordering __v, __cmp_cat::__unspec) noexcept { return __cmp_cat::type(__v._M_value & 1) == __v._M_value; } + [[nodiscard]] friend constexpr bool operator< (__cmp_cat::__unspec, partial_ordering __v) noexcept { return __v._M_value == 1; } + [[nodiscard]] friend constexpr bool operator> (__cmp_cat::__unspec, partial_ordering __v) noexcept { return __v._M_value == -1; } + [[nodiscard]] friend constexpr bool operator<=(__cmp_cat::__unspec, partial_ordering __v) noexcept { return __cmp_cat::type(__v._M_value & 1) == __v._M_value; } + [[nodiscard]] friend constexpr bool operator>=(__cmp_cat::__unspec, partial_ordering __v) noexcept { return 0 >= __v._M_value; } + [[nodiscard]] friend constexpr partial_ordering operator<=>(partial_ordering __v, __cmp_cat::__unspec) noexcept { return __v; } + [[nodiscard]] friend constexpr partial_ordering operator<=>(__cmp_cat::__unspec, partial_ordering __v) noexcept { @@ -168,53 +180,66 @@ namespace std static const weak_ordering equivalent; static const weak_ordering greater; + [[nodiscard]] constexpr operator partial_ordering() const noexcept { return partial_ordering(__cmp_cat::_Ord(_M_value)); } // comparisons + [[nodiscard]] friend constexpr bool operator==(weak_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value == 0; } + [[nodiscard]] friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default; + [[nodiscard]] friend constexpr bool operator< (weak_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value < 0; } + [[nodiscard]] friend constexpr bool operator> (weak_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value > 0; } + [[nodiscard]] friend constexpr bool operator<=(weak_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value <= 0; } + [[nodiscard]] friend constexpr bool operator>=(weak_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value >= 0; } + [[nodiscard]] friend constexpr bool operator< (__cmp_cat::__unspec, weak_ordering __v) noexcept { return 0 < __v._M_value; } + [[nodiscard]] friend constexpr bool operator> (__cmp_cat::__unspec, weak_ordering __v) noexcept { return 0 > __v._M_value; } + [[nodiscard]] friend constexpr bool operator<=(__cmp_cat::__unspec, weak_ordering __v) noexcept { return 0 <= __v._M_value; } + [[nodiscard]] friend constexpr bool operator>=(__cmp_cat::__unspec, weak_ordering __v) noexcept { return 0 >= __v._M_value; } + [[nodiscard]] friend constexpr weak_ordering operator<=>(weak_ordering __v, __cmp_cat::__unspec) noexcept { return __v; } + [[nodiscard]] friend constexpr weak_ordering operator<=>(__cmp_cat::__unspec, weak_ordering __v) noexcept { return weak_ordering(__cmp_cat::_Ord(-__v._M_value)); } @@ -246,56 +271,70 @@ namespace std static const strong_ordering equivalent; static const strong_ordering greater; + [[nodiscard]] constexpr operator partial_ordering() const noexcept { return partial_ordering(__cmp_cat::_Ord(_M_value)); } + [[nodiscard]] constexpr operator weak_ordering() const noexcept { return weak_ordering(__cmp_cat::_Ord(_M_value)); } // comparisons + [[nodiscard]] friend constexpr bool operator==(strong_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value == 0; } + [[nodiscard]] friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default; + [[nodiscard]] friend constexpr bool operator< (strong_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value < 0; } + [[nodiscard]] friend constexpr bool operator> (strong_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value > 0; } + [[nodiscard]] friend constexpr bool operator<=(strong_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value <= 0; } + [[nodiscard]] friend constexpr bool operator>=(strong_ordering __v, __cmp_cat::__unspec) noexcept { return __v._M_value >= 0; } + [[nodiscard]] friend constexpr bool operator< (__cmp_cat::__unspec, strong_ordering __v) noexcept { return 0 < __v._M_value; } + [[nodiscard]] friend constexpr bool operator> (__cmp_cat::__unspec, strong_ordering __v) noexcept { return 0 > __v._M_value; } + [[nodiscard]] friend constexpr bool operator<=(__cmp_cat::__unspec, strong_ordering __v) noexcept { return 0 <= __v._M_value; } + [[nodiscard]] friend constexpr bool operator>=(__cmp_cat::__unspec, strong_ordering __v) noexcept { return 0 >= __v._M_value; } + [[nodiscard]] friend constexpr strong_ordering operator<=>(strong_ordering __v, __cmp_cat::__unspec) noexcept { return __v; } + [[nodiscard]] friend constexpr strong_ordering operator<=>(__cmp_cat::__unspec, strong_ordering __v) noexcept { return strong_ordering(__cmp_cat::_Ord(-__v._M_value)); } @@ -316,26 +355,32 @@ namespace std // named comparison functions + [[nodiscard]] constexpr bool is_eq(partial_ordering __cmp) noexcept { return __cmp == 0; } + [[nodiscard]] constexpr bool is_neq(partial_ordering __cmp) noexcept { return __cmp != 0; } + [[nodiscard]] constexpr bool is_lt (partial_ordering __cmp) noexcept { return __cmp < 0; } + [[nodiscard]] constexpr bool is_lteq(partial_ordering __cmp) noexcept { return __cmp <= 0; } + [[nodiscard]] constexpr bool is_gt (partial_ordering __cmp) noexcept { return __cmp > 0; } + [[nodiscard]] constexpr bool is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; } @@ -505,6 +550,7 @@ namespace std constexpr auto operator()(_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::declval<_Tp>() <=> std::declval<_Up>())) + [[nodiscard]] { if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>) { @@ -628,6 +674,7 @@ namespace std constexpr strong_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) + [[nodiscard]] { /* FIXME: if constexpr (floating_point<decay_t<_Tp>>) @@ -675,6 +722,7 @@ namespace std constexpr weak_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) + [[nodiscard]] { if constexpr (floating_point<decay_t<_Tp>>) return __cmp_cust::__fp_weak_ordering(__e, __f); @@ -720,6 +768,7 @@ namespace std constexpr partial_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) + [[nodiscard]] { if constexpr (__adl_partial<_Tp, _Up>) return partial_ordering(partial_order(static_cast<_Tp&&>(__e), @@ -761,6 +810,7 @@ namespace std constexpr strong_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) + [[nodiscard]] { if constexpr (__strongly_ordered<_Tp, _Up>) return _Strong_order{}(static_cast<_Tp&&>(__e), @@ -793,6 +843,7 @@ namespace std constexpr weak_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) + [[nodiscard]] { if constexpr (__weakly_ordered<_Tp, _Up>) return _Weak_order{}(static_cast<_Tp&&>(__e), @@ -835,6 +886,7 @@ namespace std constexpr partial_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) + [[nodiscard]] { if constexpr (__partially_ordered<_Tp, _Up>) return _Partial_order{}(static_cast<_Tp&&>(__e), @@ -886,6 +938,7 @@ namespace std } template<typename _Tp, typename _Up> + [[nodiscard]] constexpr auto operator()(const _Tp& __t, const _Up& __u) const noexcept(_S_noexcept<_Tp, _Up>()) diff --git a/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc b/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc index 0ca7de0179c..f912ad399d0 100644 --- a/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc +++ b/libstdc++-v3/testsuite/18_support/comparisons/categories/zero_neg.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-options "-std=gnu++2a" } +// { dg-options "-std=gnu++2a -Wno-unused-result" } // { dg-do compile { target c++2a } } #include <compare> ^ permalink raw reply [flat|nested] 12+ messages in thread
* [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] 2021-08-04 11:55 [committed 1/2] libstdc++: Add [[nodiscard]] to iterators and related utilities Jonathan Wakely 2021-08-04 11:56 ` [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers Jonathan Wakely @ 2021-08-05 14:19 ` Jonathan Wakely 2021-08-05 14:27 ` Ville Voutilainen 2021-08-05 14:40 ` Jonathan Wakely 1 sibling, 2 replies; 12+ messages in thread From: Jonathan Wakely @ 2021-08-05 14:19 UTC (permalink / raw) To: libstdc++, gcc-patches [-- Attachment #1: Type: text/plain, Size: 422 bytes --] On 04/08/21 12:55 +0100, Jonathan Wakely wrote: >This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 >(with some minor corrections). > >The attribute is added for all modes from C++11 up, using >[[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't >be used directly. This change causes errors when -fconcepts-ts is used. Fixed like so. Tested powerpc64le-linux, committed to trunk. [-- Attachment #2: patch.txt --] [-- Type: text/x-patch, Size: 12719 bytes --] commit 7b1de3eb9ed3f8dde54732d88520292c5ad1157d Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Aug 5 13:34:00 2021 libstdc++: Move attributes that follow requires-clauses [PR101782] As explained in the PR, the grammar in the Concepts TS means that a [ token following a requires-clause is parsed as part of the logical-or-expression rather than the start of an attribute. That makes the following ill-formed when using -fconcepts-ts: template<typename T> requires foo<T> [[nodiscard]] int f(T); This change moves all attributes that follow a requires-clause to the end of the function declarator. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/101782 * include/bits/ranges_base.h (ranges::begin, ranges::end) (ranges::rbegin, ranges::rend, ranges::size, ranges::ssize) (ranges::empty, ranges::data): Move attribute to the end of the declarator. * include/bits/stl_iterator.h (__gnu_cxx::__normal_iterator) (common_iterator): Likewise for non-member operator functions. * include/std/ranges (views::all, views::filter) (views::transform, views::take, views::take_while, views::drop) (views::drop_while, views::join, views::lazy_split) (views::split, views::counted, views::common, views::reverse) (views::elements): Likewise. * testsuite/std/ranges/access/101782.cc: New test. diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 614b6edf9df..1dac9680b4f 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -110,9 +110,9 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires is_array_v<remove_reference_t<_Tp>> || __member_begin<_Tp> || __adl_begin<_Tp> - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) + [[nodiscard]] { if constexpr (is_array_v<remove_reference_t<_Tp>>) { @@ -162,9 +162,9 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_end<_Tp> || __adl_end<_Tp> - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) + [[nodiscard]] { if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>) { @@ -267,10 +267,10 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_rbegin<_Tp> || __adl_rbegin<_Tp> || __reversable<_Tp> - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) + [[nodiscard]] { if constexpr (__member_rbegin<_Tp>) return __t.rbegin(); @@ -326,10 +326,10 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_rend<_Tp> || __adl_rend<_Tp> || __reversable<_Tp> - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) + [[nodiscard]] { if constexpr (__member_rend<_Tp>) return __t.rend(); @@ -416,9 +416,9 @@ namespace ranges template<typename _Tp> requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_size<_Tp> || __adl_size<_Tp> || __sentinel_size<_Tp> - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) + [[nodiscard]] { if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>) return extent_v<remove_reference_t<_Tp>>; @@ -437,9 +437,9 @@ namespace ranges // 3403. Domain of ranges::ssize(E) doesn't match ranges::size(E) template<typename _Tp> requires requires (_Tp& __t) { _Size{}(__t); } - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(_Size{}(__t))) + [[nodiscard]] { auto __size = _Size{}(__t); using __size_type = decltype(__size); @@ -497,9 +497,9 @@ namespace ranges template<typename _Tp> requires __member_empty<_Tp> || __size0_empty<_Tp> || __eq_iter_empty<_Tp> - [[nodiscard]] constexpr bool operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) + [[nodiscard]] { if constexpr (__member_empty<_Tp>) return bool(__t.empty()); @@ -539,9 +539,9 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_data<_Tp> || __begin_data<_Tp> - [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>()) + [[nodiscard]] { if constexpr (__member_data<_Tp>) return __t.data(); diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 3773d600b8f..053ae41e9c3 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1120,19 +1120,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _IteratorL, typename _IteratorR, typename _Container> requires requires (_IteratorL __lhs, _IteratorR __rhs) { { __lhs == __rhs } -> std::convertible_to<bool>; } - [[nodiscard]] constexpr bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept(noexcept(__lhs.base() == __rhs.base())) + [[nodiscard]] { return __lhs.base() == __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> - [[nodiscard]] constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept(noexcept(std::__detail::__synth3way(__lhs.base(), __rhs.base()))) + [[nodiscard]] { return std::__detail::__synth3way(__lhs.base(), __rhs.base()); } #else // Forward iterator requirements @@ -1984,10 +1984,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _It2, sentinel_for<_It> _Sent2> requires sentinel_for<_Sent, _It2> - [[nodiscard]] friend bool operator==(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) + [[nodiscard]] { switch(__x._M_index << 2 | __y._M_index) { @@ -2007,10 +2007,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _It2, sentinel_for<_It> _Sent2> requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2> - [[nodiscard]] friend bool operator==(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) + [[nodiscard]] { switch(__x._M_index << 2 | __y._M_index) { @@ -2031,10 +2031,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2> requires sized_sentinel_for<_Sent, _It2> - [[nodiscard]] friend iter_difference_t<_It2> operator-(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) + [[nodiscard]] { switch(__x._M_index << 2 | __y._M_index) { diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 03a3778bb52..71b7dc7d295 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1126,10 +1126,10 @@ namespace views::__adaptor requires view<decay_t<_Range>> || __detail::__can_ref_view<_Range> || __detail::__can_subrange<_Range> - [[nodiscard]] constexpr auto operator()(_Range&& __r) const noexcept(_S_noexcept<_Range>()) + [[nodiscard]] { if constexpr (view<decay_t<_Range>>) return std::forward<_Range>(__r); @@ -1553,9 +1553,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pred> requires __detail::__can_filter_view<_Range, _Pred> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const + [[nodiscard]] { return filter_view(std::forward<_Range>(__r), std::forward<_Pred>(__p)); } @@ -1931,9 +1931,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Fp> requires __detail::__can_transform_view<_Range, _Fp> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Fp&& __f) const + [[nodiscard]] { return transform_view(std::forward<_Range>(__r), std::forward<_Fp>(__f)); } @@ -2113,9 +2113,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Tp> requires __detail::__can_take_view<_Range, _Tp> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Tp&& __n) const + [[nodiscard]] { return take_view(std::forward<_Range>(__r), std::forward<_Tp>(__n)); } @@ -2241,9 +2241,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pred> requires __detail::__can_take_while_view<_Range, _Pred> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const + [[nodiscard]] { return take_while_view(std::forward<_Range>(__r), std::forward<_Pred>(__p)); } @@ -2362,9 +2362,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Tp> requires __detail::__can_drop_view<_Range, _Tp> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Tp&& __n) const + [[nodiscard]] { return drop_view(std::forward<_Range>(__r), std::forward<_Tp>(__n)); } @@ -2451,9 +2451,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pred> requires __detail::__can_drop_while_view<_Range, _Pred> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const + [[nodiscard]] { return drop_while_view(std::forward<_Range>(__r), std::forward<_Pred>(__p)); @@ -2814,9 +2814,9 @@ namespace views::__adaptor { template<viewable_range _Range> requires __detail::__can_join_view<_Range> - [[nodiscard]] constexpr auto operator()(_Range&& __r) const + [[nodiscard]] { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3474. Nesting join_views is broken because of CTAD @@ -3266,9 +3266,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pattern> requires __detail::__can_lazy_split_view<_Range, _Pattern> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pattern&& __f) const + [[nodiscard]] { return lazy_split_view(std::forward<_Range>(__r), std::forward<_Pattern>(__f)); } @@ -3475,9 +3475,9 @@ namespace views::__adaptor { template<viewable_range _Range, typename _Pattern> requires __detail::__can_split_view<_Range, _Pattern> - [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pattern&& __f) const + [[nodiscard]] { return split_view(std::forward<_Range>(__r), std::forward<_Pattern>(__f)); } @@ -3497,9 +3497,9 @@ namespace views::__adaptor struct _Counted { template<input_or_output_iterator _Iter> - [[nodiscard]] constexpr auto operator()(_Iter __i, iter_difference_t<_Iter> __n) const + [[nodiscard]] { if constexpr (random_access_iterator<_Iter>) return subrange(__i, __i + __n); @@ -3619,9 +3619,9 @@ namespace views::__adaptor template<viewable_range _Range> requires __detail::__already_common<_Range> || __detail::__can_common_view<_Range> - [[nodiscard]] constexpr auto operator()(_Range&& __r) const + [[nodiscard]] { if constexpr (__detail::__already_common<_Range>) return views::all(std::forward<_Range>(__r)); @@ -3742,9 +3742,9 @@ namespace views::__adaptor requires __detail::__is_reverse_view<remove_cvref_t<_Range>> || __detail::__is_reversible_subrange<remove_cvref_t<_Range>> || __detail::__can_reverse_view<_Range> - [[nodiscard]] constexpr auto operator()(_Range&& __r) const + [[nodiscard]] { using _Tp = remove_cvref_t<_Range>; if constexpr (__detail::__is_reverse_view<_Tp>) @@ -4141,9 +4141,9 @@ namespace views::__adaptor { template<viewable_range _Range> requires __detail::__can_elements_view<_Nm, _Range> - [[nodiscard]] constexpr auto operator()(_Range&& __r) const + [[nodiscard]] { return elements_view<all_t<_Range>, _Nm>{std::forward<_Range>(__r)}; } diff --git a/libstdc++-v3/testsuite/std/ranges/access/101782.cc b/libstdc++-v3/testsuite/std/ranges/access/101782.cc new file mode 100644 index 00000000000..abb0c8dab0f --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/access/101782.cc @@ -0,0 +1,9 @@ +// { dg-options "-std=gnu++20 -fconcepts-ts" } +// { dg-do compile { target c++20 } } + +// PR testsuite/101782 +// attribute-specifier-seq cannot follow requires-clause with -fconcepts-ts + +#include <algorithm> +#include <iterator> +#include <ranges> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] 2021-08-05 14:19 ` [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] Jonathan Wakely @ 2021-08-05 14:27 ` Ville Voutilainen 2021-08-05 14:40 ` Jonathan Wakely 1 sibling, 0 replies; 12+ messages in thread From: Ville Voutilainen @ 2021-08-05 14:27 UTC (permalink / raw) To: Jonathan Wakely; +Cc: libstdc++, gcc-patches List On Thu, 5 Aug 2021 at 17:21, Jonathan Wakely via Libstdc++ <libstdc++@gcc.gnu.org> wrote: > > On 04/08/21 12:55 +0100, Jonathan Wakely wrote: > >This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 > >(with some minor corrections). > > > >The attribute is added for all modes from C++11 up, using > >[[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't > >be used directly. > > This change causes errors when -fconcepts-ts is used. Fixed like so. But this makes the attribute appertain to the function type, not to the function. It's also ill-formed: "The attribute-token nodiscard may be applied to the declarator-id in a function declaration or to the declaration of a class or enumeration. " Your change makes nodiscard be applied to the function declaration, not to the declarator-id. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] 2021-08-05 14:19 ` [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] Jonathan Wakely 2021-08-05 14:27 ` Ville Voutilainen @ 2021-08-05 14:40 ` Jonathan Wakely 2021-08-05 18:02 ` Jonathan Wakely 1 sibling, 1 reply; 12+ messages in thread From: Jonathan Wakely @ 2021-08-05 14:40 UTC (permalink / raw) To: libstdc++, gcc-patches On 05/08/21 15:19 +0100, Jonathan Wakely wrote: >On 04/08/21 12:55 +0100, Jonathan Wakely wrote: >>This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 >>(with some minor corrections). >> >>The attribute is added for all modes from C++11 up, using >>[[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't >>be used directly. > >This change causes errors when -fconcepts-ts is used. Fixed like so. > >Tested powerpc64le-linux, committed to trunk. > >commit 7b1de3eb9ed3f8dde54732d88520292c5ad1157d >Author: Jonathan Wakely <jwakely@redhat.com> >Date: Thu Aug 5 13:34:00 2021 > > libstdc++: Move attributes that follow requires-clauses [PR101782] > > As explained in the PR, the grammar in the Concepts TS means that a [ > token following a requires-clause is parsed as part of the > logical-or-expression rather than the start of an attribute. That makes > the following ill-formed when using -fconcepts-ts: > > template<typename T> requires foo<T> [[nodiscard]] int f(T); > > This change moves all attributes that follow a requires-clause to the > end of the function declarator. Except that as Jakub pointed out, putting it there doesn't work. It needs to be: template<typename T> requires foo<T> int f [[nodiscard]] (T); At least the testsuite isn't failing now, but the attributes I moved have no effect. I'll fix it ... some time. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] 2021-08-05 14:40 ` Jonathan Wakely @ 2021-08-05 18:02 ` Jonathan Wakely 2021-08-06 13:29 ` Jonathan Wakely 0 siblings, 1 reply; 12+ messages in thread From: Jonathan Wakely @ 2021-08-05 18:02 UTC (permalink / raw) To: libstdc++, gcc-patches [-- Attachment #1: Type: text/plain, Size: 1550 bytes --] On 05/08/21 15:40 +0100, Jonathan Wakely wrote: >On 05/08/21 15:19 +0100, Jonathan Wakely wrote: >>On 04/08/21 12:55 +0100, Jonathan Wakely wrote: >>>This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 >>>(with some minor corrections). >>> >>>The attribute is added for all modes from C++11 up, using >>>[[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't >>>be used directly. >> >>This change causes errors when -fconcepts-ts is used. Fixed like so. >> >>Tested powerpc64le-linux, committed to trunk. >> > >>commit 7b1de3eb9ed3f8dde54732d88520292c5ad1157d >>Author: Jonathan Wakely <jwakely@redhat.com> >>Date: Thu Aug 5 13:34:00 2021 >> >> libstdc++: Move attributes that follow requires-clauses [PR101782] >> As explained in the PR, the grammar in the Concepts TS means that a [ >> token following a requires-clause is parsed as part of the >> logical-or-expression rather than the start of an attribute. That makes >> the following ill-formed when using -fconcepts-ts: >> template<typename T> requires foo<T> [[nodiscard]] int f(T); >> This change moves all attributes that follow a requires-clause to the >> end of the function declarator. > > >Except that as Jakub pointed out, putting it there doesn't work. > >It needs to be: > > template<typename T> requires foo<T> int f [[nodiscard]] (T); > >At least the testsuite isn't failing now, but the attributes I moved >have no effect. I'll fix it ... some time. This should be correct now. Tested powerpc64le-linux, pushed to trunk. [-- Attachment #2: patch.txt --] [-- Type: text/x-patch, Size: 14051 bytes --] commit c8b024fa4b76bfd914e96dd3cecfbb6ee8e91316 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Aug 5 16:46:00 2021 libstdc++: Move [[nodiscard]] attributes again [PR101782] Where I moved these nodiscard attributes to made them apply to the function type, not to the function. This meant they no longer generated the desired -Wunused-result warnings, and were ill-formed with Clang (but only a pedwarn with GCC). Clang also detected ill-formed attributes in <queue> which this fixes. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/101782 * include/bits/ranges_base.h (ranges::begin, ranges::end) (ranges::rbegin, ranges::rend, ranges::size, ranges::ssize) (ranges::empty, ranges::data): Move attribute after the declarator-id instead of at the end of the declarator. * include/bits/stl_iterator.h (__gnu_cxx::__normal_iterator): Move attributes back to the start of the function declarator, but move the requires-clause to the end. (common_iterator): Move attribute after the declarator-id. * include/bits/stl_queue.h (queue): Remove ill-formed attributes from friend declaration that are not definitions. * include/std/ranges (views::all, views::filter) (views::transform, views::take, views::take_while, views::drop) (views::drop_while, views::join, views::lazy_split) (views::split, views::counted, views::common, views::reverse) (views::elements): Move attributes after the declarator-id. diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 1dac9680b4f..49c7d9c9f06 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -111,8 +111,7 @@ namespace ranges requires is_array_v<remove_reference_t<_Tp>> || __member_begin<_Tp> || __adl_begin<_Tp> constexpr auto - operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) - [[nodiscard]] + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { if constexpr (is_array_v<remove_reference_t<_Tp>>) { @@ -163,8 +162,7 @@ namespace ranges requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_end<_Tp> || __adl_end<_Tp> constexpr auto - operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) - [[nodiscard]] + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>) { @@ -268,9 +266,8 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires __member_rbegin<_Tp> || __adl_rbegin<_Tp> || __reversable<_Tp> constexpr auto - operator()(_Tp&& __t) const + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) - [[nodiscard]] { if constexpr (__member_rbegin<_Tp>) return __t.rbegin(); @@ -327,9 +324,8 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires __member_rend<_Tp> || __adl_rend<_Tp> || __reversable<_Tp> constexpr auto - operator()(_Tp&& __t) const + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) - [[nodiscard]] { if constexpr (__member_rend<_Tp>) return __t.rend(); @@ -417,8 +413,7 @@ namespace ranges requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_size<_Tp> || __adl_size<_Tp> || __sentinel_size<_Tp> constexpr auto - operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) - [[nodiscard]] + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>) return extent_v<remove_reference_t<_Tp>>; @@ -438,8 +433,7 @@ namespace ranges template<typename _Tp> requires requires (_Tp& __t) { _Size{}(__t); } constexpr auto - operator()(_Tp&& __t) const noexcept(noexcept(_Size{}(__t))) - [[nodiscard]] + operator()[[nodiscard]](_Tp&& __t) const noexcept(noexcept(_Size{}(__t))) { auto __size = _Size{}(__t); using __size_type = decltype(__size); @@ -498,8 +492,7 @@ namespace ranges requires __member_empty<_Tp> || __size0_empty<_Tp> || __eq_iter_empty<_Tp> constexpr bool - operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) - [[nodiscard]] + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { if constexpr (__member_empty<_Tp>) return bool(__t.empty()); @@ -540,8 +533,7 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires __member_data<_Tp> || __begin_data<_Tp> constexpr auto - operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>()) - [[nodiscard]] + operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp>()) { if constexpr (__member_data<_Tp>) return __t.data(); diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 053ae41e9c3..c5b02408c1c 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1118,21 +1118,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_three_way_comparison template<typename _IteratorL, typename _IteratorR, typename _Container> - requires requires (_IteratorL __lhs, _IteratorR __rhs) - { { __lhs == __rhs } -> std::convertible_to<bool>; } + [[nodiscard]] constexpr bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept(noexcept(__lhs.base() == __rhs.base())) - [[nodiscard]] + requires requires { + { __lhs.base() == __rhs.base() } -> std::convertible_to<bool>; + } { return __lhs.base() == __rhs.base(); } template<typename _IteratorL, typename _IteratorR, typename _Container> + [[nodiscard]] constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept(noexcept(std::__detail::__synth3way(__lhs.base(), __rhs.base()))) - [[nodiscard]] { return std::__detail::__synth3way(__lhs.base(), __rhs.base()); } #else // Forward iterator requirements @@ -1985,9 +1986,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _It2, sentinel_for<_It> _Sent2> requires sentinel_for<_Sent, _It2> friend bool - operator==(const common_iterator& __x, - const common_iterator<_It2, _Sent2>& __y) - [[nodiscard]] + operator== [[nodiscard]] (const common_iterator& __x, + const common_iterator<_It2, _Sent2>& __y) { switch(__x._M_index << 2 | __y._M_index) { @@ -2008,9 +2008,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _It2, sentinel_for<_It> _Sent2> requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2> friend bool - operator==(const common_iterator& __x, - const common_iterator<_It2, _Sent2>& __y) - [[nodiscard]] + operator== [[nodiscard]] (const common_iterator& __x, + const common_iterator<_It2, _Sent2>& __y) { switch(__x._M_index << 2 | __y._M_index) { @@ -2032,9 +2031,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2> requires sized_sentinel_for<_Sent, _It2> friend iter_difference_t<_It2> - operator-(const common_iterator& __x, - const common_iterator<_It2, _Sent2>& __y) - [[nodiscard]] + operator- [[nodiscard]] (const common_iterator& __x, + const common_iterator<_It2, _Sent2>& __y) { switch(__x._M_index << 2 | __y._M_index) { diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index 363868fe0a6..41ffc50d380 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -107,18 +107,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template<typename _Tp1, typename _Seq1> - _GLIBCXX_NODISCARD friend bool operator==(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); template<typename _Tp1, typename _Seq1> - _GLIBCXX_NODISCARD friend bool operator<(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); #if __cpp_lib_three_way_comparison template<typename _Tp1, three_way_comparable _Seq1> - [[nodiscard]] friend compare_three_way_result_t<_Seq1> operator<=>(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); #endif diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 71b7dc7d295..fb8905fab08 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1127,9 +1127,8 @@ namespace views::__adaptor || __detail::__can_ref_view<_Range> || __detail::__can_subrange<_Range> constexpr auto - operator()(_Range&& __r) const + operator() [[nodiscard]] (_Range&& __r) const noexcept(_S_noexcept<_Range>()) - [[nodiscard]] { if constexpr (view<decay_t<_Range>>) return std::forward<_Range>(__r); @@ -1554,8 +1553,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Pred> requires __detail::__can_filter_view<_Range, _Pred> constexpr auto - operator()(_Range&& __r, _Pred&& __p) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Pred&& __p) const { return filter_view(std::forward<_Range>(__r), std::forward<_Pred>(__p)); } @@ -1932,8 +1930,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Fp> requires __detail::__can_transform_view<_Range, _Fp> constexpr auto - operator()(_Range&& __r, _Fp&& __f) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Fp&& __f) const { return transform_view(std::forward<_Range>(__r), std::forward<_Fp>(__f)); } @@ -2114,8 +2111,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Tp> requires __detail::__can_take_view<_Range, _Tp> constexpr auto - operator()(_Range&& __r, _Tp&& __n) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Tp&& __n) const { return take_view(std::forward<_Range>(__r), std::forward<_Tp>(__n)); } @@ -2242,8 +2238,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Pred> requires __detail::__can_take_while_view<_Range, _Pred> constexpr auto - operator()(_Range&& __r, _Pred&& __p) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Pred&& __p) const { return take_while_view(std::forward<_Range>(__r), std::forward<_Pred>(__p)); } @@ -2363,8 +2358,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Tp> requires __detail::__can_drop_view<_Range, _Tp> constexpr auto - operator()(_Range&& __r, _Tp&& __n) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Tp&& __n) const { return drop_view(std::forward<_Range>(__r), std::forward<_Tp>(__n)); } @@ -2452,8 +2446,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Pred> requires __detail::__can_drop_while_view<_Range, _Pred> constexpr auto - operator()(_Range&& __r, _Pred&& __p) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Pred&& __p) const { return drop_while_view(std::forward<_Range>(__r), std::forward<_Pred>(__p)); @@ -2815,8 +2808,7 @@ namespace views::__adaptor template<viewable_range _Range> requires __detail::__can_join_view<_Range> constexpr auto - operator()(_Range&& __r) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r) const { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 3474. Nesting join_views is broken because of CTAD @@ -3267,8 +3259,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Pattern> requires __detail::__can_lazy_split_view<_Range, _Pattern> constexpr auto - operator()(_Range&& __r, _Pattern&& __f) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Pattern&& __f) const { return lazy_split_view(std::forward<_Range>(__r), std::forward<_Pattern>(__f)); } @@ -3476,8 +3467,7 @@ namespace views::__adaptor template<viewable_range _Range, typename _Pattern> requires __detail::__can_split_view<_Range, _Pattern> constexpr auto - operator()(_Range&& __r, _Pattern&& __f) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r, _Pattern&& __f) const { return split_view(std::forward<_Range>(__r), std::forward<_Pattern>(__f)); } @@ -3498,8 +3488,7 @@ namespace views::__adaptor { template<input_or_output_iterator _Iter> constexpr auto - operator()(_Iter __i, iter_difference_t<_Iter> __n) const - [[nodiscard]] + operator() [[nodiscard]] (_Iter __i, iter_difference_t<_Iter> __n) const { if constexpr (random_access_iterator<_Iter>) return subrange(__i, __i + __n); @@ -3620,8 +3609,7 @@ namespace views::__adaptor requires __detail::__already_common<_Range> || __detail::__can_common_view<_Range> constexpr auto - operator()(_Range&& __r) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r) const { if constexpr (__detail::__already_common<_Range>) return views::all(std::forward<_Range>(__r)); @@ -3743,8 +3731,7 @@ namespace views::__adaptor || __detail::__is_reversible_subrange<remove_cvref_t<_Range>> || __detail::__can_reverse_view<_Range> constexpr auto - operator()(_Range&& __r) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r) const { using _Tp = remove_cvref_t<_Range>; if constexpr (__detail::__is_reverse_view<_Tp>) @@ -4142,8 +4129,7 @@ namespace views::__adaptor template<viewable_range _Range> requires __detail::__can_elements_view<_Nm, _Range> constexpr auto - operator()(_Range&& __r) const - [[nodiscard]] + operator() [[nodiscard]] (_Range&& __r) const { return elements_view<all_t<_Range>, _Nm>{std::forward<_Range>(__r)}; } ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] 2021-08-05 18:02 ` Jonathan Wakely @ 2021-08-06 13:29 ` Jonathan Wakely 0 siblings, 0 replies; 12+ messages in thread From: Jonathan Wakely @ 2021-08-06 13:29 UTC (permalink / raw) To: libstdc++, gcc-patches [-- Attachment #1: Type: text/plain, Size: 1692 bytes --] On 05/08/21 19:02 +0100, Jonathan Wakely wrote: >On 05/08/21 15:40 +0100, Jonathan Wakely wrote: >>On 05/08/21 15:19 +0100, Jonathan Wakely wrote: >>>On 04/08/21 12:55 +0100, Jonathan Wakely wrote: >>>>This adds [[nodiscard]] throughout <iterator>, as proposed by P2377R0 >>>>(with some minor corrections). >>>> >>>>The attribute is added for all modes from C++11 up, using >>>>[[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't >>>>be used directly. >>> >>>This change causes errors when -fconcepts-ts is used. Fixed like so. >>> >>>Tested powerpc64le-linux, committed to trunk. >>> >> >>>commit 7b1de3eb9ed3f8dde54732d88520292c5ad1157d >>>Author: Jonathan Wakely <jwakely@redhat.com> >>>Date: Thu Aug 5 13:34:00 2021 >>> >>> libstdc++: Move attributes that follow requires-clauses [PR101782] >>> As explained in the PR, the grammar in the Concepts TS means that a [ >>> token following a requires-clause is parsed as part of the >>> logical-or-expression rather than the start of an attribute. That makes >>> the following ill-formed when using -fconcepts-ts: >>> template<typename T> requires foo<T> [[nodiscard]] int f(T); >>> This change moves all attributes that follow a requires-clause to the >>> end of the function declarator. >> >> >>Except that as Jakub pointed out, putting it there doesn't work. >> >>It needs to be: >> >> template<typename T> requires foo<T> int f [[nodiscard]] (T); >> >>At least the testsuite isn't failing now, but the attributes I moved >>have no effect. I'll fix it ... some time. > >This should be correct now. Except I needed to move the ones I added to <compare> as well. Tested powerpc64le-linux, pushed to trunk. [-- Attachment #2: patch.txt --] [-- Type: text/x-patch, Size: 3707 bytes --] commit c2a984a3570b908a44a35e43bb48f0a05196156a Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Aug 6 13:43:26 2021 libstdc++: Also move the [[nodiscard]] attributes in <compare> Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * libsupc++/compare (compare_three_way, strong_order) (weak_order, partial_order, compare_strong_order_fallback) (compare_weak_order_fallback, compare_partial_order_fallback): Move nodiscard attributes to correct location. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index faeff641437..5aee89e3a6e 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -548,9 +548,8 @@ namespace std template<typename _Tp, typename _Up> requires three_way_comparable_with<_Tp, _Up> constexpr auto - operator()(_Tp&& __t, _Up&& __u) const + operator() [[nodiscard]] (_Tp&& __t, _Up&& __u) const noexcept(noexcept(std::declval<_Tp>() <=> std::declval<_Up>())) - [[nodiscard]] { if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>) { @@ -672,9 +671,8 @@ namespace std template<typename _Tp, __decayed_same_as<_Tp> _Up> requires __strongly_ordered<_Tp, _Up> constexpr strong_ordering - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) - [[nodiscard]] { /* FIXME: if constexpr (floating_point<decay_t<_Tp>>) @@ -720,9 +718,8 @@ namespace std template<typename _Tp, __decayed_same_as<_Tp> _Up> requires __weakly_ordered<_Tp, _Up> constexpr weak_ordering - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) - [[nodiscard]] { if constexpr (floating_point<decay_t<_Tp>>) return __cmp_cust::__fp_weak_ordering(__e, __f); @@ -766,9 +763,8 @@ namespace std template<typename _Tp, __decayed_same_as<_Tp> _Up> requires __partially_ordered<_Tp, _Up> constexpr partial_ordering - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) - [[nodiscard]] { if constexpr (__adl_partial<_Tp, _Up>) return partial_ordering(partial_order(static_cast<_Tp&&>(__e), @@ -808,9 +804,8 @@ namespace std template<typename _Tp, __decayed_same_as<_Tp> _Up> requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up> constexpr strong_ordering - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) - [[nodiscard]] { if constexpr (__strongly_ordered<_Tp, _Up>) return _Strong_order{}(static_cast<_Tp&&>(__e), @@ -841,9 +836,8 @@ namespace std template<typename _Tp, __decayed_same_as<_Tp> _Up> requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up> constexpr weak_ordering - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) - [[nodiscard]] { if constexpr (__weakly_ordered<_Tp, _Up>) return _Weak_order{}(static_cast<_Tp&&>(__e), @@ -884,9 +878,8 @@ namespace std template<typename _Tp, __decayed_same_as<_Tp> _Up> requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up> constexpr partial_ordering - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) - [[nodiscard]] { if constexpr (__partially_ordered<_Tp, _Up>) return _Partial_order{}(static_cast<_Tp&&>(__e), ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-08-06 13:29 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-08-04 11:55 [committed 1/2] libstdc++: Add [[nodiscard]] to iterators and related utilities Jonathan Wakely 2021-08-04 11:56 ` [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers Jonathan Wakely 2021-08-04 12:00 ` Jonathan Wakely 2021-08-05 12:09 ` Christophe Lyon 2021-08-05 12:13 ` Ville Voutilainen 2021-08-05 14:21 ` Jonathan Wakely 2021-08-05 14:38 ` Jonathan Wakely 2021-08-05 14:19 ` [committed] libstdc++: Move attributes that follow requires-clauses [PR101782] Jonathan Wakely 2021-08-05 14:27 ` Ville Voutilainen 2021-08-05 14:40 ` Jonathan Wakely 2021-08-05 18:02 ` Jonathan Wakely 2021-08-06 13:29 ` Jonathan Wakely
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).