diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-02-26 13:09:02 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-02-28 11:27:46 +0000 |
commit | 2d8cd712b17e88f2935237665799d0c72b7ce1b6 (patch) | |
tree | 81b6f4a53538dc96648db89050f25eeacabc66cd /libstdc++-v3/include | |
parent | cf918498ab7c717e3c6badab44340117af53ec35 (diff) | |
download | gcc-2d8cd712b17e88f2935237665799d0c72b7ce1b6.zip gcc-2d8cd712b17e88f2935237665799d0c72b7ce1b6.tar.gz gcc-2d8cd712b17e88f2935237665799d0c72b7ce1b6.tar.bz2 |
libstdc++: Add more nodiscard uses in <vector>
Add [[nodiscard]] to vector::at and to comparison operators.
libstdc++-v3/ChangeLog:
* include/bits/stl_bvector.h (vector<bool, A>::at): Add
nodiscard.
* include/bits/stl_vector.h (vector<T, A>::at): Likewise.
(operator==, operator<=>, operator<, operator!=, operator>)
(operator<=, operator>=): Likewise.
* include/debug/vector (operator==, operator<=>, operator<)
(operator!=, operator>, operator<=, operator>=): Likewise.
* testsuite/23_containers/vector/nodiscard.cc: New test.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/stl_bvector.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 18 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/vector | 8 |
3 files changed, 18 insertions, 12 deletions
diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index aa5644b..2c8b892 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -1101,7 +1101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } public: - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference at(size_type __n) { @@ -1109,7 +1109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return (*this)[__n]; } - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference at(size_type __n) const { diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 6a9543e..a8d387f 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -1172,7 +1172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * is first checked that it is in the range of the vector. The * function throws out_of_range if the check fails. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference at(size_type __n) { @@ -1191,7 +1191,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * is first checked that it is in the range of the vector. The * function throws out_of_range if the check fails. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference at(size_type __n) const { @@ -2042,7 +2042,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * and if corresponding elements compare equal. */ template<typename _Tp, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return (__x.size() == __y.size() @@ -2061,7 +2061,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * `<` and `>=` etc. */ template<typename _Tp, typename _Alloc> - _GLIBCXX20_CONSTEXPR + [[nodiscard]] _GLIBCXX20_CONSTEXPR inline __detail::__synth3way_t<_Tp> operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { @@ -2082,32 +2082,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * See std::lexicographical_compare() for how the determination is made. */ template<typename _Tp, typename _Alloc> - inline bool + _GLIBCXX_NODISCARD inline bool operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } /// Based on operator== template<typename _Tp, typename _Alloc> - inline bool + _GLIBCXX_NODISCARD inline bool operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Alloc> - inline bool + _GLIBCXX_NODISCARD inline bool operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template<typename _Tp, typename _Alloc> - inline bool + _GLIBCXX_NODISCARD inline bool operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Alloc> - inline bool + _GLIBCXX_NODISCARD inline bool operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x < __y); } #endif // three-way comparison diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 5a0fc80..2168229 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -866,7 +866,7 @@ namespace __debug }; template<typename _Tp, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) @@ -874,35 +874,41 @@ namespace __debug #if __cpp_lib_three_way_comparison template<typename _Tp, typename _Alloc> + [[nodiscard]] constexpr __detail::__synth3way_t<_Tp> operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return __x._M_base() <=> __y._M_base(); } #else template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator!=(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) { return __lhs._M_base() != __rhs._M_base(); } template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) { return __lhs._M_base() < __rhs._M_base(); } template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<=(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) { return __lhs._M_base() <= __rhs._M_base(); } template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>=(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) { return __lhs._M_base() >= __rhs._M_base(); } template<typename _Tp, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) |