Skip to content

Commit 2980120

Browse files
committed
Fix
1 parent c47f4d5 commit 2980120

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

libcxx/include/bitset

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>
791791
}
792792

793793
template <size_t _Size>
794-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
794+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
795795
std::fill_n(__base::__make_iter(0), _Size, true);
796796
return *this;
797797
}
@@ -928,23 +928,23 @@ bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {
928928
}
929929

930930
template <size_t _Size>
931-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
931+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
932932
operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
933933
bitset<_Size> __r = __x;
934934
__r &= __y;
935935
return __r;
936936
}
937937

938938
template <size_t _Size>
939-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
939+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
940940
operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
941941
bitset<_Size> __r = __x;
942942
__r |= __y;
943943
return __r;
944944
}
945945

946946
template <size_t _Size>
947-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
947+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
948948
operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
949949
bitset<_Size> __r = __x;
950950
__r ^= __y;
@@ -953,7 +953,9 @@ operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
953953

954954
template <size_t _Size>
955955
struct hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
956-
_LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
956+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT {
957+
return __bs.__hash_code();
958+
}
957959
};
958960

959961
template <class _CharT, class _Traits, size_t _Size>

libcxx/test/libcxx/utilities/template.bitset/nodiscard.verify.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// <bitset>
1210

1311
// Check that functions are marked [[nodiscard]]
@@ -18,8 +16,8 @@
1816
#include "test_allocator.h"
1917

2018
void test() {
21-
std::bitset<10> bs;
22-
const std::bitset<10> cbs;
19+
std::bitset<11> bs;
20+
const std::bitset<11> cbs;
2321

2422
// std::bitset<>::reference operator~() const noexcept;
2523
~bs[0]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -34,7 +32,7 @@ void test() {
3432
struct CharTraits : public std::char_traits<char> {};
3533

3634
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
37-
bs.to_string<char, CharTraits, test_allocator<char>>();
35+
bs.to_string<char, CharTraits, test_allocator<char> >();
3836
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
3937
bs.to_string<char, CharTraits>();
4038
#if !defined(TEST_HAS_NO_WIDE_CHARACTERS)
@@ -52,4 +50,12 @@ void test() {
5250
bs.none(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
5351
bs << 1; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
5452
bs >> 1; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
53+
54+
bs & bs; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
55+
bs | bs; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
56+
bs ^ bs; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
57+
58+
std::hash<std::bitset<11> > hash;
59+
60+
hash(bs); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
5561
}

0 commit comments

Comments
 (0)