diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-08-26 16:22:21 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-08-31 10:28:46 +0100 |
commit | b911ca4231a366ddfd026f190b126bd517f4e640 (patch) | |
tree | 494d307eeb67a6eefcd2b7f5081ac7b727b6a2ee /libstdc++-v3 | |
parent | beec815f26bcb7041a824e0f7180855d364e2271 (diff) | |
download | gcc-b911ca4231a366ddfd026f190b126bd517f4e640.zip gcc-b911ca4231a366ddfd026f190b126bd517f4e640.tar.gz gcc-b911ca4231a366ddfd026f190b126bd517f4e640.tar.bz2 |
libstdc++: Add [[nodiscard]] attribute to <string> and <string_view>
libstdc++-v3/ChangeLog:
* include/bits/basic_string.h (basic_string): Add nodiscard
attribute to all relevant functions.
* include/std/string_view (basic_string_view): Likewise.
* testsuite/21_strings/basic_string/capacity/1.cc: Cast unused
results to void.
* testsuite/21_strings/basic_string/capacity/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string/capacity/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/char/self_move.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/char/21674.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string/element_access/wchar_t/21674.cc:
Likewise.
* testsuite/21_strings/basic_string/lwg2758.cc: Likewise.
* testsuite/21_strings/basic_string/lwg2946.cc: Likewise.
* testsuite/21_strings/basic_string/operations/contains/nonnull.cc:
Add -Wno-unused-result to options.
* testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc:
Likewise.
* testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc:
Likewise.
* testsuite/21_strings/basic_string/operators/char/1.cc: Cast
unused results to void.
* testsuite/21_strings/basic_string/operators/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/capacity/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc:
Likewise.
Add -Wno-unused-result to options.
* testsuite/21_strings/basic_string_view/operations/ends_with/nonnull.cc:
Likewise.
* testsuite/21_strings/basic_string_view/operations/starts_with/nonnull.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc: Cast
unused results to void.
* testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/sungetc/char/1.cc: Likewise.
* testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc:
Likewise.
Diffstat (limited to 'libstdc++-v3')
29 files changed, 279 insertions, 157 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 9d8b415..0df64ea 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -942,7 +942,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write iterator that points to the first character in * the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_M_data()); } @@ -951,7 +951,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) iterator that points to the first * character in the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_M_data()); } @@ -960,7 +960,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write iterator that points one past the last * character in the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR iterator end() _GLIBCXX_NOEXCEPT { return iterator(_M_data() + this->size()); } @@ -969,7 +969,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) iterator that points one past the * last character in the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_M_data() + this->size()); } @@ -979,7 +979,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * character in the %string. Iteration is done in reverse element * order. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(this->end()); } @@ -989,7 +989,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * to the last character in the %string. Iteration is done in * reverse element order. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(this->end()); } @@ -999,7 +999,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first character in the %string. Iteration is done in reverse * element order. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(this->begin()); } @@ -1009,7 +1009,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * to one before the first character in the %string. Iteration * is done in reverse element order. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(this->begin()); } @@ -1019,7 +1019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) iterator that points to the first * character in the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_iterator cbegin() const noexcept { return const_iterator(this->_M_data()); } @@ -1028,7 +1028,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) iterator that points one past the * last character in the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_iterator cend() const noexcept { return const_iterator(this->_M_data() + this->size()); } @@ -1038,7 +1038,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * to the last character in the %string. Iteration is done in * reverse element order. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(this->end()); } @@ -1048,7 +1048,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * to one before the first character in the %string. Iteration * is done in reverse element order. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reverse_iterator crend() const noexcept { return const_reverse_iterator(this->begin()); } @@ -1058,20 +1058,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 // Capacity: /// Returns the number of characters in the string, not including any /// null-termination. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type size() const _GLIBCXX_NOEXCEPT { return _M_string_length; } /// Returns the number of characters in the string, not including any /// null-termination. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type length() const _GLIBCXX_NOEXCEPT { return _M_string_length; } /// Returns the size() of the largest possible %string. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type max_size() const _GLIBCXX_NOEXCEPT { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; } @@ -1127,7 +1127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns the total number of characters that the %string can hold * before needing to allocate more memory. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type capacity() const _GLIBCXX_NOEXCEPT { @@ -1194,7 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * out_of_range lookups are not defined. (For checked lookups * see at().) */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT { @@ -1212,7 +1212,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * out_of_range lookups are not defined. (For checked lookups * see at().) */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference operator[](size_type __pos) { @@ -1234,7 +1234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first checked that it is in the range of the string. The function * throws out_of_range if the check fails. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference at(size_type __n) const { @@ -1256,7 +1256,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first checked that it is in the range of the string. The function * throws out_of_range if the check fails. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference at(size_type __n) { @@ -1273,7 +1273,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write reference to the data at the first * element of the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference front() noexcept { @@ -1285,7 +1285,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) reference to the data at the first * element of the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference front() const noexcept { @@ -1297,7 +1297,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write reference to the data at the last * element of the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference back() noexcept { @@ -1309,7 +1309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) reference to the data at the * last element of the %string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference back() const noexcept { @@ -2549,7 +2549,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * This is a handle to internal data. Do not modify or dire things may * happen. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const _CharT* c_str() const _GLIBCXX_NOEXCEPT { return _M_data(); } @@ -2562,7 +2562,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * allows modifying the contents use @c &str[0] instead, * (or in C++17 the non-const @c str.data() overload). */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const _CharT* data() const _GLIBCXX_NOEXCEPT { return _M_data(); } @@ -2574,7 +2574,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * This is a pointer to the character sequence held by the string. * Modifying the characters in the sequence is allowed. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _CharT* data() noexcept { return _M_data(); } @@ -2583,7 +2583,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 /** * @brief Return copy of allocator used to construct this string. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR allocator_type get_allocator() const _GLIBCXX_NOEXCEPT { return _M_get_allocator(); } @@ -2600,7 +2600,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * returns the index where it begins. If not found, returns * npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find(const _CharT* __s, size_type __pos, size_type __n) const _GLIBCXX_NOEXCEPT; @@ -2615,7 +2615,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * this string. If found, returns the index where it begins. If not * found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find(const basic_string& __str, size_type __pos = 0) const _GLIBCXX_NOEXCEPT @@ -2629,7 +2629,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Index of start of first occurrence. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, size_type> find(const _Tp& __svt, size_type __pos = 0) const noexcept(is_same<_Tp, __sv_type>::value) @@ -2649,7 +2649,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * __s within this string. If found, returns the index where * it begins. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT { @@ -2667,7 +2667,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * this string. If found, returns the index where it was * found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; @@ -2681,7 +2681,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * __str within this string. If found, returns the index where * it begins. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type rfind(const basic_string& __str, size_type __pos = npos) const _GLIBCXX_NOEXCEPT @@ -2695,7 +2695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Index of start of last occurrence. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, size_type> rfind(const _Tp& __svt, size_type __pos = npos) const noexcept(is_same<_Tp, __sv_type>::value) @@ -2717,7 +2717,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * returns the index where it begins. If not found, returns * npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _GLIBCXX_NOEXCEPT; @@ -2732,7 +2732,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @a __s within this string. If found, returns the index * where it begins. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type rfind(const _CharT* __s, size_type __pos = npos) const { @@ -2750,7 +2750,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * this string. If found, returns the index where it was * found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; @@ -2765,7 +2765,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * returns the index where it was found. If not found, returns * npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _GLIBCXX_NOEXCEPT @@ -2780,7 +2780,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Index of first occurrence. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, size_type> find_first_of(const _Tp& __svt, size_type __pos = 0) const noexcept(is_same<_Tp, __sv_type>::value) @@ -2802,7 +2802,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * found, returns the index where it was found. If not found, * returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _GLIBCXX_NOEXCEPT; @@ -2817,7 +2817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * characters of @a __s within this string. If found, returns * the index where it was found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_of(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT @@ -2838,7 +2838,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * * Note: equivalent to find(__c, __pos). */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT { return this->find(__c, __pos); } @@ -2854,7 +2854,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * returns the index where it was found. If not found, returns * npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _GLIBCXX_NOEXCEPT @@ -2869,7 +2869,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Index of last occurrence. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, size_type> find_last_of(const _Tp& __svt, size_type __pos = npos) const noexcept(is_same<_Tp, __sv_type>::value) @@ -2891,7 +2891,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * found, returns the index where it was found. If not found, * returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _GLIBCXX_NOEXCEPT; @@ -2906,7 +2906,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * characters of @a __s within this string. If found, returns * the index where it was found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_of(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT @@ -2927,7 +2927,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * * Note: equivalent to rfind(__c, __pos). */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT { return this->rfind(__c, __pos); } @@ -2942,7 +2942,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * in @a __str within this string. If found, returns the index where it * was found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _GLIBCXX_NOEXCEPT @@ -2957,8 +2957,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Index of first occurrence. */ template<typename _Tp> + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, size_type> - _GLIBCXX20_CONSTEXPR find_first_not_of(const _Tp& __svt, size_type __pos = 0) const noexcept(is_same<_Tp, __sv_type>::value) { @@ -2979,7 +2979,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * this string. If found, returns the index where it was * found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _GLIBCXX_NOEXCEPT; @@ -2994,7 +2994,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * contained in @a __s within this string. If found, returns * the index where it was found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT @@ -3013,7 +3013,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * other than @a __c within this string. If found, returns the * index where it was found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; @@ -3029,7 +3029,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * returns the index where it was found. If not found, returns * npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _GLIBCXX_NOEXCEPT @@ -3044,7 +3044,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Index of last occurrence. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, size_type> find_last_not_of(const _Tp& __svt, size_type __pos = npos) const noexcept(is_same<_Tp, __sv_type>::value) @@ -3066,7 +3066,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * If found, returns the index where it was found. If not found, * returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _GLIBCXX_NOEXCEPT; @@ -3081,7 +3081,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * returns the index where it was found. If not found, returns * npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT @@ -3100,7 +3100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @a __c within this string. If found, returns the index where it was * found. If not found, returns npos. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR size_type find_last_not_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; @@ -3117,7 +3117,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * short, use the remainder of the characters. If @a __pos is * beyond the end of the string, out_of_range is thrown. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR basic_string substr(size_type __pos = 0, size_type __n = npos) const { return basic_string(*this, @@ -3137,7 +3137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * If the result of the comparison is nonzero returns it, * otherwise the shorter one is ordered first. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR int compare(const basic_string& __str) const { @@ -3158,7 +3158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Integer < 0, 0, or > 0. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, int> compare(const _Tp& __svt) const noexcept(is_same<_Tp, __sv_type>::value) @@ -3183,7 +3183,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Integer < 0, 0, or > 0. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, int> compare(size_type __pos, size_type __n, const _Tp& __svt) const noexcept(is_same<_Tp, __sv_type>::value) @@ -3203,7 +3203,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * @return Integer < 0, 0, or > 0. */ template<typename _Tp> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _If_sv<_Tp, int> compare(size_type __pos1, size_type __n1, const _Tp& __svt, size_type __pos2, size_type __n2 = npos) const @@ -3234,7 +3234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * result of the comparison is nonzero returns it, otherwise * the shorter one is ordered first. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR int compare(size_type __pos, size_type __n, const basic_string& __str) const { @@ -3271,7 +3271,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * If the result of the comparison is nonzero returns it, * otherwise the shorter one is ordered first. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2 = npos) const @@ -3302,7 +3302,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * comparison is nonzero returns it, otherwise the shorter one is * ordered first. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR int compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT { @@ -3337,7 +3337,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the comparison is nonzero returns it, otherwise the shorter * one is ordered first. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR int compare(size_type __pos, size_type __n1, const _CharT* __s) const { @@ -3376,7 +3376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * NB: s must have at least n2 characters, '\\0' has * no special meaning. */ - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR int compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const @@ -3392,43 +3392,49 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 } #if __cplusplus >= 202002L + [[nodiscard]] constexpr bool starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept { return __sv_type(this->data(), this->size()).starts_with(__x); } + [[nodiscard]] constexpr bool starts_with(_CharT __x) const noexcept { return __sv_type(this->data(), this->size()).starts_with(__x); } - [[__gnu__::__nonnull__]] + [[nodiscard, __gnu__::__nonnull__]] constexpr bool starts_with(const _CharT* __x) const noexcept { return __sv_type(this->data(), this->size()).starts_with(__x); } + [[nodiscard]] constexpr bool ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept { return __sv_type(this->data(), this->size()).ends_with(__x); } + [[nodiscard]] constexpr bool ends_with(_CharT __x) const noexcept { return __sv_type(this->data(), this->size()).ends_with(__x); } - [[__gnu__::__nonnull__]] + [[nodiscard, __gnu__::__nonnull__]] constexpr bool ends_with(const _CharT* __x) const noexcept { return __sv_type(this->data(), this->size()).ends_with(__x); } #endif // C++20 #if __cplusplus > 202002L + [[nodiscard]] constexpr bool contains(basic_string_view<_CharT, _Traits> __x) const noexcept { return __sv_type(this->data(), this->size()).contains(__x); } + [[nodiscard]] constexpr bool contains(_CharT __x) const noexcept { return __sv_type(this->data(), this->size()).contains(__x); } - [[__gnu__::__nonnull__]] + [[nodiscard, __gnu__::__nonnull__]] constexpr bool contains(const _CharT* __x) const noexcept { return __sv_type(this->data(), this->size()).contains(__x); } @@ -3483,7 +3489,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return New string with value of @a __lhs followed by @a __rhs. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR basic_string<_CharT, _Traits, _Alloc> operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3500,7 +3506,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return New string with value of @a __lhs followed by @a __rhs. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR basic_string<_CharT,_Traits,_Alloc> operator+(const _CharT* __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); @@ -3512,7 +3518,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return New string with @a __lhs followed by @a __rhs. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR basic_string<_CharT,_Traits,_Alloc> operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); @@ -3523,7 +3529,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return New string with @a __lhs followed by @a __rhs. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3540,7 +3546,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return New string with @a __lhs followed by @a __rhs. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) { @@ -3553,7 +3559,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 #if __cplusplus >= 201103L template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3567,7 +3573,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 { return std::move(__rhs.insert(0, __lhs)); } template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, basic_string<_CharT, _Traits, _Alloc>&& __rhs) @@ -3590,28 +3596,28 @@ _GLIBCXX_END_NAMESPACE_CXX11 } template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(const _CharT* __lhs, basic_string<_CharT, _Traits, _Alloc>&& __rhs) { return std::move(__rhs.insert(0, __lhs)); } template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(_CharT __lhs, basic_string<_CharT, _Traits, _Alloc>&& __rhs) { return std::move(__rhs.insert(0, 1, __lhs)); } template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, const _CharT* __rhs) { return std::move(__lhs.append(__rhs)); } template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline basic_string<_CharT, _Traits, _Alloc> operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, _CharT __rhs) @@ -3626,7 +3632,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3643,7 +3649,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3661,6 +3667,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * greater than, or incomparable with `__rhs`. */ template<typename _CharT, typename _Traits, typename _Alloc> + [[nodiscard]] constexpr auto operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept @@ -3675,6 +3682,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * greater than, or incomparable with `__rhs`. */ template<typename _CharT, typename _Traits, typename _Alloc> + [[nodiscard]] constexpr auto operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) noexcept @@ -3688,6 +3696,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3701,6 +3710,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3714,6 +3724,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator!=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3726,6 +3737,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3739,6 +3751,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs precedes @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3752,6 +3765,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs precedes @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3764,6 +3778,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs precedes @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3777,6 +3792,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs follows @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3790,6 +3806,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs follows @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3802,6 +3819,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs follows @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3815,6 +3833,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3828,6 +3847,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3840,6 +3860,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator<=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3853,6 +3874,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -3866,6 +3888,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) @@ -3878,6 +3901,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. */ template<typename _CharT, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD inline bool operator>=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) @@ -4060,6 +4084,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 // DR 1261. Insufficent overloads for to_string / to_wstring + _GLIBCXX_NODISCARD inline string to_string(int __val) #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32 @@ -4074,6 +4099,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return __str; } + _GLIBCXX_NODISCARD inline string to_string(unsigned __val) #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32 @@ -4085,6 +4111,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return __str; } + _GLIBCXX_NODISCARD inline string to_string(long __val) #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32 @@ -4099,6 +4126,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return __str; } + _GLIBCXX_NODISCARD inline string to_string(unsigned long __val) #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32 @@ -4110,6 +4138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return __str; } + _GLIBCXX_NODISCARD inline string to_string(long long __val) { @@ -4122,6 +4151,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 return __str; } + _GLIBCXX_NODISCARD inline string to_string(unsigned long long __val) { @@ -4133,6 +4163,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 #if _GLIBCXX_USE_C99_STDIO // NB: (v)snprintf vs sprintf. + _GLIBCXX_NODISCARD inline string to_string(float __val) { @@ -4142,6 +4173,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 "%f", __val); } + _GLIBCXX_NODISCARD inline string to_string(double __val) { @@ -4151,6 +4183,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 "%f", __val); } + _GLIBCXX_NODISCARD inline string to_string(long double __val) { @@ -4202,40 +4235,47 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF // DR 1261. + _GLIBCXX_NODISCARD inline wstring to_wstring(int __val) { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int), L"%d", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(unsigned __val) { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(unsigned), L"%u", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(long __val) { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long), L"%ld", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(unsigned long __val) { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(unsigned long), L"%lu", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(long long __val) { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long long), L"%lld", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(unsigned long long __val) { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(unsigned long long), L"%llu", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(float __val) { @@ -4245,6 +4285,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 L"%f", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(double __val) { @@ -4254,6 +4295,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 L"%f", __val); } + _GLIBCXX_NODISCARD inline wstring to_wstring(long double __val) { @@ -4287,6 +4329,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __str_hash_base : public __hash_base<size_t, _StrT> { + [[__nodiscard__]] size_t operator()(const _StrT& __s) const noexcept { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(_CharT)); } diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 5b96ffe..2604af2 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -129,7 +129,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr basic_string_view(const basic_string_view&) noexcept = default; - __attribute__((__nonnull__)) constexpr + [[__gnu__::__nonnull__]] + constexpr basic_string_view(const _CharT* __str) noexcept : _M_len{traits_type::length(__str)}, _M_str{__str} @@ -172,54 +173,64 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif // C++23 #endif // C++20 - constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default; // [string.view.iterators], iterator support + [[nodiscard]] constexpr const_iterator begin() const noexcept { return this->_M_str; } + [[nodiscard]] constexpr const_iterator end() const noexcept { return this->_M_str + this->_M_len; } + [[nodiscard]] constexpr const_iterator cbegin() const noexcept { return this->_M_str; } + [[nodiscard]] constexpr const_iterator cend() const noexcept { return this->_M_str + this->_M_len; } + [[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(this->end()); } + [[nodiscard]] constexpr const_reverse_iterator rend() const noexcept { return const_reverse_iterator(this->begin()); } + [[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(this->end()); } + [[nodiscard]] constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(this->begin()); } // [string.view.capacity], capacity + [[nodiscard]] constexpr size_type size() const noexcept { return this->_M_len; } + [[nodiscard]] constexpr size_type length() const noexcept { return _M_len; } + [[nodiscard]] constexpr size_type max_size() const noexcept { @@ -227,12 +238,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION / sizeof(value_type) / 4; } - [[nodiscard]] constexpr bool + [[nodiscard]] + constexpr bool empty() const noexcept { return this->_M_len == 0; } // [string.view.access], element access + [[nodiscard]] constexpr const_reference operator[](size_type __pos) const noexcept { @@ -240,6 +253,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *(this->_M_str + __pos); } + [[nodiscard]] constexpr const_reference at(size_type __pos) const { @@ -250,6 +264,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *(this->_M_str + __pos); } + [[nodiscard]] constexpr const_reference front() const noexcept { @@ -257,6 +272,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this->_M_str; } + [[nodiscard]] constexpr const_reference back() const noexcept { @@ -264,6 +280,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *(this->_M_str + this->_M_len - 1); } + [[nodiscard]] constexpr const_pointer data() const noexcept { return this->_M_str; } @@ -305,6 +322,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __rlen; } + [[nodiscard]] constexpr basic_string_view substr(size_type __pos = 0, size_type __n = npos) const noexcept(false) { @@ -313,6 +331,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return basic_string_view{_M_str + __pos, __rlen}; } + [[nodiscard]] constexpr int compare(basic_string_view __str) const noexcept { @@ -323,10 +342,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __ret; } + [[nodiscard]] constexpr int compare(size_type __pos1, size_type __n1, basic_string_view __str) const { return this->substr(__pos1, __n1).compare(__str); } + [[nodiscard]] constexpr int compare(size_type __pos1, size_type __n1, basic_string_view __str, size_type __pos2, size_type __n2) const @@ -334,14 +355,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); } - __attribute__((__nonnull__)) constexpr int + [[nodiscard, __gnu__::__nonnull__]] + constexpr int compare(const _CharT* __str) const noexcept { return this->compare(basic_string_view{__str}); } - __attribute__((__nonnull__)) constexpr int + [[nodiscard, __gnu__::__nonnull__]] + constexpr int compare(size_type __pos1, size_type __n1, const _CharT* __str) const { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); } + [[nodiscard]] constexpr int compare(size_type __pos1, size_type __n1, const _CharT* __str, size_type __n2) const noexcept(false) @@ -352,19 +376,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L #define __cpp_lib_starts_ends_with 201711L + [[nodiscard]] constexpr bool starts_with(basic_string_view __x) const noexcept { return this->substr(0, __x.size()) == __x; } + [[nodiscard]] constexpr bool starts_with(_CharT __x) const noexcept { return !this->empty() && traits_type::eq(this->front(), __x); } - [[__gnu__::__nonnull__]] + [[nodiscard, __gnu__::__nonnull__]] constexpr bool starts_with(const _CharT* __x) const noexcept { return this->starts_with(basic_string_view(__x)); } + [[nodiscard]] constexpr bool ends_with(basic_string_view __x) const noexcept { @@ -374,11 +401,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION && traits_type::compare(end() - __xlen, __x.data(), __xlen) == 0; } + [[nodiscard]] constexpr bool ends_with(_CharT __x) const noexcept { return !this->empty() && traits_type::eq(this->back(), __x); } - [[__gnu__::__nonnull__]] + [[nodiscard, __gnu__::__nonnull__]] constexpr bool ends_with(const _CharT* __x) const noexcept { return this->ends_with(basic_string_view(__x)); } @@ -386,15 +414,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 202002L #define __cpp_lib_string_contains 202011L + [[nodiscard]] constexpr bool contains(basic_string_view __x) const noexcept { return this->find(__x) != npos; } + [[nodiscard]] constexpr bool contains(_CharT __x) const noexcept { return this->find(__x) != npos; } - [[__gnu__::__nonnull__]] + [[nodiscard, __gnu__::__nonnull__]] constexpr bool contains(const _CharT* __x) const noexcept { return this->find(__x) != npos; } @@ -402,99 +432,123 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // [string.view.find], searching + [[nodiscard]] constexpr size_type find(basic_string_view __str, size_type __pos = 0) const noexcept { return this->find(__str._M_str, __pos, __str._M_len); } + [[nodiscard]] constexpr size_type find(_CharT __c, size_type __pos = 0) const noexcept; + [[nodiscard]] constexpr size_type find(const _CharT* __str, size_type __pos, size_type __n) const noexcept; - __attribute__((__nonnull__)) constexpr size_type + [[nodiscard, __gnu__::__nonnull__]] + constexpr size_type find(const _CharT* __str, size_type __pos = 0) const noexcept { return this->find(__str, __pos, traits_type::length(__str)); } + [[nodiscard]] constexpr size_type rfind(basic_string_view __str, size_type __pos = npos) const noexcept { return this->rfind(__str._M_str, __pos, __str._M_len); } + [[nodiscard]] constexpr size_type rfind(_CharT __c, size_type __pos = npos) const noexcept; + [[nodiscard]] constexpr size_type rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept; - __attribute__((__nonnull__)) constexpr size_type + [[nodiscard, __gnu__::__nonnull__]] + constexpr size_type rfind(const _CharT* __str, size_type __pos = npos) const noexcept { return this->rfind(__str, __pos, traits_type::length(__str)); } + [[nodiscard]] constexpr size_type find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept { return this->find_first_of(__str._M_str, __pos, __str._M_len); } + [[nodiscard]] constexpr size_type find_first_of(_CharT __c, size_type __pos = 0) const noexcept { return this->find(__c, __pos); } + [[nodiscard]] constexpr size_type find_first_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept; - __attribute__((__nonnull__)) constexpr size_type + [[nodiscard, __gnu__::__nonnull__]] + constexpr size_type find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept { return this->find_first_of(__str, __pos, traits_type::length(__str)); } + [[nodiscard]] constexpr size_type find_last_of(basic_string_view __str, size_type __pos = npos) const noexcept { return this->find_last_of(__str._M_str, __pos, __str._M_len); } + [[nodiscard]] constexpr size_type find_last_of(_CharT __c, size_type __pos=npos) const noexcept { return this->rfind(__c, __pos); } + [[nodiscard]] constexpr size_type find_last_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept; - __attribute__((__nonnull__)) constexpr size_type + [[nodiscard, __gnu__::__nonnull__]] + constexpr size_type find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept { return this->find_last_of(__str, __pos, traits_type::length(__str)); } + [[nodiscard]] constexpr size_type find_first_not_of(basic_string_view __str, size_type __pos = 0) const noexcept { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); } + [[nodiscard]] constexpr size_type find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept; + [[nodiscard]] constexpr size_type find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept; - __attribute__((__nonnull__)) constexpr size_type + [[nodiscard, __gnu__::__nonnull__]] + constexpr size_type find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept { return this->find_first_not_of(__str, __pos, traits_type::length(__str)); } + [[nodiscard]] constexpr size_type find_last_not_of(basic_string_view __str, size_type __pos = npos) const noexcept { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); } + [[nodiscard]] constexpr size_type find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept; + [[nodiscard]] constexpr size_type find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept; - __attribute__((__nonnull__)) constexpr size_type + [[nodiscard, __gnu__::__nonnull__]] + constexpr size_type find_last_not_of(const _CharT* __str, size_type __pos = npos) const noexcept { @@ -539,12 +593,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // type (see N3766). template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator==(basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.size() == __y.size() && __x.compare(__y) == 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator==(basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -553,6 +609,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_three_way_comparison template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr auto operator<=>(basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept @@ -560,6 +617,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr auto operator<=>(basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -568,18 +626,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); } #else template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.size() == __y.size() && __x.compare(__y) == 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator!=(basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return !(__x == __y); } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator!=(basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -587,18 +648,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !(__x == __y); } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return !(__x == __y); } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator< (basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) < 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator< (basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -606,18 +670,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.compare(__y) < 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) < 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator> (basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) > 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator> (basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -625,18 +692,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.compare(__y) > 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) > 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator<=(basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) <= 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator<=(basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -644,18 +714,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.compare(__y) <= 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) <= 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator>=(basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept { return __x.compare(__y) >= 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator>=(basic_string_view<_CharT, _Traits> __x, __type_identity_t<basic_string_view<_CharT, _Traits>> __y) @@ -663,6 +736,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.compare(__y) >= 0; } template<typename _CharT, typename _Traits> + [[nodiscard]] constexpr bool operator>=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x, basic_string_view<_CharT, _Traits> __y) noexcept @@ -696,6 +770,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<string_view> : public __hash_base<size_t, string_view> { + [[nodiscard]] size_t operator()(const string_view& __str) const noexcept { return std::_Hash_impl::hash(__str.data(), __str.length()); } @@ -709,6 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<wstring_view> : public __hash_base<size_t, wstring_view> { + [[nodiscard]] size_t operator()(const wstring_view& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), @@ -724,6 +800,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<u8string_view> : public __hash_base<size_t, u8string_view> { + [[nodiscard]] size_t operator()(const u8string_view& __str) const noexcept { return std::_Hash_impl::hash(__str.data(), __str.length()); } @@ -738,6 +815,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<u16string_view> : public __hash_base<size_t, u16string_view> { + [[nodiscard]] size_t operator()(const u16string_view& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), @@ -752,6 +830,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<u32string_view> : public __hash_base<size_t, u32string_view> { + [[nodiscard]] size_t operator()(const u32string_view& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc index 45af457..1ae4d3d 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/1.cc @@ -175,7 +175,7 @@ void test01() sz03 = str02.size(); sz04 = str02.length(); VERIFY( sz03 == sz04 ); - str02.c_str(); + (void) str02.c_str(); sz03 = str02.size(); sz04 = str02.length(); VERIFY( sz03 == sz04 ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc index 244a795..1da273b 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc @@ -74,15 +74,15 @@ void test01() sz01 = str01.size(); sz02 = str01.length(); VERIFY( sz01 == sz02 ); - str01.c_str(); + (void) str01.c_str(); sz01 = str01.size(); sz02 = str01.length(); VERIFY( sz01 == sz02 ); sz01 = str01.length(); - str01.c_str(); + (void) str01.c_str(); str011 = str01 + "_addendum_"; - str01.c_str(); + (void) str01.c_str(); sz02 = str01.length(); VERIFY( sz01 == sz02 ); sz02 = str011.length(); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc index 5cb682e..6f03e34 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc @@ -71,15 +71,15 @@ void test01() sz01 = str01.size(); sz02 = str01.length(); VERIFY( sz01 == sz02 ); - str01.c_str(); + (void) str01.c_str(); sz01 = str01.size(); sz02 = str01.length(); VERIFY( sz01 == sz02 ); sz01 = str01.length(); - str01.c_str(); + (void) str01.c_str(); str011 = str01 + L"_addendum_"; - str01.c_str(); + (void) str01.c_str(); sz02 = str01.length(); VERIFY( sz01 == sz02 ); sz02 = str011.length(); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/self_move.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/self_move.cc index d37fe39..ddd9aea 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/self_move.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/self_move.cc @@ -32,7 +32,7 @@ test(const char* s) String s3 __attribute__((unused)) = s1; s1 = std::move(s1); - s1.begin(); // causes COW string to "leak" + (void) s1.begin(); // causes COW string to "leak" s1 = std::move(s1); String s4 __attribute__((unused)) = s1; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc index 7fb4323..5a176c0 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/1.cc @@ -53,7 +53,7 @@ void test01(void) cref cref3 = str01.at(csz01 - 1); VERIFY( cref3 == 'a' ); try { - str01.at(csz01); + (void) str01.at(csz01); VERIFY( false ); // Should not get here, as exception thrown. } catch(std::out_of_range& fail) { @@ -68,7 +68,7 @@ void test01(void) ref ref3 = str02.at(csz02 - 1); VERIFY( ref3 == 'a' ); try { - str02.at(csz02); + (void) str02.at(csz02); VERIFY( false ); // Should not get here, as exception thrown. } catch(std::out_of_range& fail) { diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/21674.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/21674.cc index a5a129b..3ff8d51 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/21674.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/21674.cc @@ -27,5 +27,5 @@ int main() { typedef std::string string_type; string_type s; - s[1]; // abort + (void) s[1]; // abort } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc index 9bb5dcb..f9a07ab 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/1.cc @@ -53,7 +53,7 @@ void test01(void) cref cref3 = str01.at(csz01 - 1); VERIFY( cref3 == L'a' ); try { - str01.at(csz01); + (void) str01.at(csz01); VERIFY( false ); // Should not get here, as exception thrown. } catch(std::out_of_range& fail) { @@ -68,7 +68,7 @@ void test01(void) ref ref3 = str02.at(csz02 - 1); VERIFY( ref3 == L'a' ); try { - str02.at(csz02); + (void) str02.at(csz02); VERIFY( false ); // Should not get here, as exception thrown. } catch(std::out_of_range& fail) { diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/21674.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/21674.cc index 974e6b2..fc023a8 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/21674.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/21674.cc @@ -27,5 +27,5 @@ int main() { typedef std::wstring string_type; string_type s; - s[1]; // abort + (void) s[1]; // abort } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc b/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc index 45d514b..a9dcd9a 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/lwg2758.cc @@ -40,6 +40,6 @@ int main() x.replace(0, 3, "foo", 0, 3); x.replace(0, 3, cs, 0, 3); x = "bar"; - x.compare(0, 3, "foo", 0, 3); - x.compare(0, 3, cs, 0, 3); + (void) x.compare(0, 3, "foo", 0, 3); + (void) x.compare(0, 3, cs, 0, 3); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/lwg2946.cc b/libstdc++-v3/testsuite/21_strings/basic_string/lwg2946.cc index 3cbaf17..6e308ba 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/lwg2946.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/lwg2946.cc @@ -29,12 +29,12 @@ int main() s.insert(0, {"abc", 1}); s.replace(0, 1, {"abc", 1}); s.replace(s.begin(), s.begin(), {"abc", 1}); - s.find({"abc", 1}); - s.rfind({"abc", 1}); - s.find_first_of({"abc", 1}); - s.find_last_of({"abc", 1}); - s.find_first_not_of({"abc", 1}); - s.find_last_not_of({"abc", 1}); - s.compare({"abc", 1}); - s.compare(0, 1, {"abc", 1}); + (void) s.find({"abc", 1}); + (void) s.rfind({"abc", 1}); + (void) s.find_first_of({"abc", 1}); + (void) s.find_last_of({"abc", 1}); + (void) s.find_first_not_of({"abc", 1}); + (void) s.find_last_not_of({"abc", 1}); + (void) s.compare({"abc", 1}); + (void) s.compare(0, 1, {"abc", 1}); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/nonnull.cc index e987cb7..41bb391 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/nonnull.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++23 -Wnonnull -O0" } +// { dg-options "-std=gnu++23 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++23 } } #include <string> diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc index 1f2a156..32f3449 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++20 -Wnonnull -O0" } +// { dg-options "-std=gnu++20 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++20 } } #include <string> diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc index 8514359..9e0d665 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++20 -Wnonnull -O0" } +// { dg-options "-std=gnu++20 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++20 } } #include <string> diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc index 704d2f6..be3e41a 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/char/1.cc @@ -35,12 +35,12 @@ int test01(void) // 2:8-chars_8-chars_ // The following triggers -Wstringop-overread. See PR 103332. str1 = std::string("8-chars_") + "8-chars_"; - str1.c_str(); + (void) str1.c_str(); // printf("1:%s\n", str1.c_str()); VERIFY( str1 == "8-chars_8-chars_" ); str2 = str1 + "7-chars"; // printf("2:%s\n", str1.c_str()); //str1 is gone - str1.c_str(); + (void) str1.c_str(); VERIFY( str1 == "8-chars_8-chars_" ); return 0; } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc index 4020950..df3ff7c 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operators/wchar_t/1.cc @@ -32,11 +32,11 @@ int test01(void) // 1:8-chars_8-chars_ // 2:8-chars_8-chars_ str1 = std::wstring(L"8-chars_") + L"8-chars_"; - str1.c_str(); + (void) str1.c_str(); // wprintf("1:%s\n", str1.c_str()); str2 = str1 + L"7-chars"; // wprintf("2:%s\n", str1.c_str()); //str1 is gone - str1.c_str(); + (void) str1.c_str(); return 0; } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc index 0376d91..3d162c6 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/capacity/1.cc @@ -137,7 +137,7 @@ test01() sz03 = str02.size(); sz04 = str02.length(); VERIFY( sz03 == sz04 ); - str02.data(); + (void) str02.data(); sz03 = str02.size(); sz04 = str02.length(); VERIFY( sz03 == sz04 ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc index 5de62ec..b27e7d7 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/1.cc @@ -49,7 +49,7 @@ test01() VERIFY( cref3 == 'a' ); try { - str01.at(csz01); + (void) str01.at(csz01); VERIFY( false ); // Should not get here, as exception thrown. } catch (std::out_of_range& fail) diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/2.cc index e8f9db2..834d3f6 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/2.cc @@ -27,5 +27,5 @@ main() { typedef std::string_view string_view_type; string_view_type s; - s[0]; // abort + (void) s[0]; // abort } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc index 9877cd8..e9df872 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc @@ -49,7 +49,7 @@ test01() VERIFY( cref3 == L'a' ); try { - str01.at(csz01); + (void) str01.at(csz01); VERIFY( false ); // Should not get here, as exception thrown. } catch (std::out_of_range& fail) diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc index 23daa7a..840de84 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc @@ -29,5 +29,5 @@ main() { typedef std::wstring_view string_view_type; string_view_type s; - s[0]; // abort + (void) s[0]; // abort } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc index c0d274f..fafadcc 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++23 -Wnonnull -O0" } +// { dg-options "-std=gnu++23 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++23 } } #include <string_view> diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/ends_with/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/ends_with/nonnull.cc index 09a9997..50437bb 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/ends_with/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/ends_with/nonnull.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++20 -Wnonnull -O0" } +// { dg-options "-std=gnu++20 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++20 } } #include <string_view> diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/starts_with/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/starts_with/nonnull.cc index c47f1da..fedba28a 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/starts_with/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/operations/starts_with/nonnull.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++20 -Wnonnull -O0" } +// { dg-options "-std=gnu++20 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++20 } } #include <string_view> diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc index 1e8c5fd..2296fd1 100644 --- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc @@ -41,18 +41,18 @@ void test04() // PUT strb_03.str(str_01); //reset - strb_03.str().length(); - strb_03.str().length(); + (void) strb_03.str().length(); + (void) strb_03.str().length(); // streamsize sputn(const char_typs* s, streamsize n) // write up to n chars to out_cur from s, returning number assigned // NB *sputn will happily put '\0' into your stream if you give it a chance* str_tmp = strb_03.str(); - str_tmp.length(); + (void) str_tmp.length(); strb_03.sputn("racadabras", 10);//"abracadabras or what?" - strb_03.str().length(); + (void) strb_03.str().length(); strb_03.sputn(", i wanna reach out and", 10); - strb_03.str().length(); + (void) strb_03.str().length(); str_tmp = strb_02.str(); strb_02.sputn("racadabra", 10); diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc index 6acc0f24..c44a535 100644 --- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc @@ -41,18 +41,18 @@ void test04() // PUT strb_03.str(str_01); //reset - strb_03.str().length(); - strb_03.str().length(); + (void) strb_03.str().length(); + (void) strb_03.str().length(); // streamsize sputn(const char_typs* s, streamsize n) // write up to n chars to out_cur from s, returning number assigned // NB *sputn will happily put '\0' into your stream if you give it a chance* str_tmp = strb_03.str(); - str_tmp.length(); + (void) str_tmp.length(); strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" - strb_03.str().length(); + (void) strb_03.str().length(); strb_03.sputn(L", i wanna reach out and", 10); - strb_03.str().length(); + (void) strb_03.str().length(); str_tmp = strb_02.str(); strb_02.sputn(L"racadabra", 10); diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc index 2a3a28b..b4cdb17 100644 --- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc @@ -41,18 +41,18 @@ void test04() // PUT strb_03.str(str_01); //reset - strb_03.str().length(); - strb_03.str().length(); + (void) strb_03.str().length(); + (void) strb_03.str().length(); // streamsize sputn(const char_typs* s, streamsize n) // write up to n chars to out_cur from s, returning number assigned // NB *sputn will happily put '\0' into your stream if you give it a chance* str_tmp = strb_03.str(); - str_tmp.length(); + (void) str_tmp.length(); strb_03.sputn("racadabras", 10);//"abracadabras or what?" - strb_03.str().length(); + (void) strb_03.str().length(); strb_03.sputn(", i wanna reach out and", 10); - strb_03.str().length(); + (void) strb_03.str().length(); str_tmp = strb_02.str(); strb_02.sputn("racadabra", 10); diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc index 5f20e2c..eb0ae5e 100644 --- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc @@ -41,18 +41,18 @@ void test04() // PUT strb_03.str(str_01); //reset - strb_03.str().length(); - strb_03.str().length(); + (void) strb_03.str().length(); + (void) strb_03.str().length(); // streamsize sputn(const char_typs* s, streamsize n) // write up to n chars to out_cur from s, returning number assigned // NB *sputn will happily put '\0' into your stream if you give it a chance* str_tmp = strb_03.str(); - str_tmp.length(); + (void) str_tmp.length(); strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" - strb_03.str().length(); + (void) strb_03.str().length(); strb_03.sputn(L", i wanna reach out and", 10); - strb_03.str().length(); + (void) strb_03.str().length(); str_tmp = strb_02.str(); strb_02.sputn(L"racadabra", 10); |