Skip to content

Commit dc948b5

Browse files
committed
Fixed and improved
1 parent aa16e23 commit dc948b5

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

libcxx/test/libcxx/diagnostics/set.nodiscard.verify.cpp

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,31 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// Check that functions are marked [[nodiscard]]
1210

1311
#include <set>
1412

1513
#include "test_macros.h"
1614

17-
template <typename T>
15+
#if TEST_STD_VER >= 14
1816
struct TransparentKey {
19-
T t;
20-
21-
constexpr explicit operator T() const { return t; }
17+
explicit operator int() const;
2218
};
2319

2420
struct TransparentCompare {
2521
using is_transparent = void; // This makes the comparator transparent
2622

27-
template <typename T>
28-
constexpr bool operator()(const T& t, const TransparentKey<T>& transparent) const {
29-
return t < transparent.t;
30-
}
23+
bool operator()(const int&, const TransparentKey&) const;
3124

32-
template <typename T>
33-
constexpr bool operator()(const TransparentKey<T>& transparent, const T& t) const {
34-
return transparent.t < t;
35-
}
25+
bool operator()(const TransparentKey&, const int&) const;
3626

37-
template <typename T>
38-
constexpr bool operator()(const T& t1, const T& t2) const {
39-
return t1 < t2;
40-
}
27+
bool operator()(const int&, const int&) const;
4128
};
29+
#endif
4230

4331
void test() {
44-
std::set<int, TransparentCompare> s;
45-
const std::set<int, TransparentCompare> cs{};
32+
std::set<int> s;
33+
const std::set<int> cs;
4634

4735
s.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
4836
cs.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -77,35 +65,38 @@ void test() {
7765
s.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
7866
cs.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
7967
#if TEST_STD_VER >= 14
80-
TransparentKey<int> tkey;
68+
std::set<int, TransparentCompare> ts;
69+
const std::set<int, TransparentCompare> cts{};
70+
71+
TransparentKey tkey;
8172

82-
s.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
83-
cs.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
73+
ts.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
74+
cts.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
8475
#endif
8576

8677
s.count(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
8778
#if TEST_STD_VER >= 14
88-
s.count(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
79+
ts.count(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
8980
#endif
9081

9182
s.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
9283
cs.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
9384
#if TEST_STD_VER >= 14
94-
s.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
95-
cs.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
85+
ts.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
86+
cts.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
9687
#endif
9788

9889
s.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
9990
cs.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
10091
#if TEST_STD_VER >= 14
101-
s.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
102-
cs.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
92+
ts.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
93+
cts.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
10394
#endif
10495

10596
s.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
10697
cs.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
10798
#if TEST_STD_VER >= 14
108-
s.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
109-
cs.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
99+
ts.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
100+
cts.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
110101
#endif
111102
}

0 commit comments

Comments
 (0)