|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | | -// UNSUPPORTED: c++03 |
10 | | - |
11 | 9 | // Check that functions are marked [[nodiscard]] |
12 | 10 |
|
13 | 11 | #include <set> |
14 | 12 |
|
15 | 13 | #include "test_macros.h" |
16 | 14 |
|
17 | | -template <typename T> |
| 15 | +#if TEST_STD_VER >= 14 |
18 | 16 | struct TransparentKey { |
19 | | - T t; |
20 | | - |
21 | | - constexpr explicit operator T() const { return t; } |
| 17 | + explicit operator int() const; |
22 | 18 | }; |
23 | 19 |
|
24 | 20 | struct TransparentCompare { |
25 | 21 | using is_transparent = void; // This makes the comparator transparent |
26 | 22 |
|
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; |
31 | 24 |
|
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; |
36 | 26 |
|
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; |
41 | 28 | }; |
| 29 | +#endif |
42 | 30 |
|
43 | 31 | 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; |
46 | 34 |
|
47 | 35 | s.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
48 | 36 | cs.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
@@ -77,35 +65,38 @@ void test() { |
77 | 65 | s.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
78 | 66 | cs.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
79 | 67 | #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; |
81 | 72 |
|
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}} |
84 | 75 | #endif |
85 | 76 |
|
86 | 77 | s.count(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
87 | 78 | #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}} |
89 | 80 | #endif |
90 | 81 |
|
91 | 82 | s.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
92 | 83 | cs.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
93 | 84 | #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}} |
96 | 87 | #endif |
97 | 88 |
|
98 | 89 | s.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
99 | 90 | cs.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
100 | 91 | #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}} |
103 | 94 | #endif |
104 | 95 |
|
105 | 96 | s.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
106 | 97 | cs.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
107 | 98 | #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}} |
110 | 101 | #endif |
111 | 102 | } |
0 commit comments