|
14 | 14 |
|
15 | 15 | #include "test_macros.h" |
16 | 16 |
|
| 17 | +#if TEST_STD_VER >= 14 |
17 | 18 | template <typename T> |
18 | 19 | struct TransparentKey { |
19 | | - T t; |
20 | | - |
21 | | - constexpr explicit operator T() const { return t; } |
| 20 | + explicit operator T() const; |
22 | 21 | }; |
23 | 22 |
|
24 | 23 | struct TransparentCompare { |
25 | 24 | using is_transparent = void; // This makes the comparator transparent |
26 | 25 |
|
27 | 26 | template <typename T> |
28 | | - constexpr bool operator()(const T& t, const TransparentKey<T>& transparent) const { |
29 | | - return t < transparent.t; |
30 | | - } |
| 27 | + bool operator()(const T&, const TransparentKey<T>&) const; |
31 | 28 |
|
32 | 29 | template <typename T> |
33 | | - constexpr bool operator()(const TransparentKey<T>& transparent, const T& t) const { |
34 | | - return transparent.t < t; |
35 | | - } |
| 30 | + bool operator()(const TransparentKey<T>&, const T&) const; |
36 | 31 |
|
37 | 32 | template <typename T> |
38 | | - constexpr bool operator()(const T& t1, const T& t2) const { |
39 | | - return t1 < t2; |
40 | | - } |
| 33 | + bool operator()(const T&, const T&) const; |
41 | 34 | }; |
| 35 | +#endif |
42 | 36 |
|
43 | 37 | void test() { |
44 | | - std::map<int, int, TransparentCompare> m; |
45 | | - const std::map<int, int, TransparentCompare> cm{}; |
| 38 | + std::map<int, int> m; |
| 39 | + const std::map<int, int> cm; |
46 | 40 |
|
47 | 41 | m.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
48 | 42 | cm.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
@@ -92,40 +86,43 @@ void test() { |
92 | 86 | m.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
93 | 87 | cm.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
94 | 88 | #if TEST_STD_VER >= 14 |
| 89 | + std::map<int, int, TransparentCompare> tm; |
| 90 | + const std::map<int, int, TransparentCompare> ctm{}; |
| 91 | + |
95 | 92 | TransparentKey<int> tkey; |
96 | 93 |
|
97 | | - m.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
98 | | - cm.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 94 | + tm.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 95 | + ctm.find(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
99 | 96 | #endif |
100 | 97 |
|
101 | 98 | m.count(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
102 | 99 | #if TEST_STD_VER >= 14 |
103 | | - m.count(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 100 | + tm.count(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
104 | 101 | #endif |
105 | 102 |
|
106 | 103 | #if TEST_STD_VER >= 20 |
107 | | - m.contains(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
108 | | - m.contains(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 104 | + m.contains(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 105 | + tm.contains(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
109 | 106 | #endif |
110 | 107 |
|
111 | 108 | m.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
112 | 109 | cm.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
113 | 110 | #if TEST_STD_VER >= 14 |
114 | | - m.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
115 | | - cm.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 111 | + tm.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 112 | + ctm.lower_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
116 | 113 | #endif |
117 | 114 |
|
118 | 115 | m.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
119 | 116 | cm.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
120 | 117 | #if TEST_STD_VER >= 14 |
121 | | - m.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
122 | | - cm.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 118 | + tm.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 119 | + ctm.upper_bound(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
123 | 120 | #endif |
124 | 121 |
|
125 | 122 | m.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
126 | 123 | cm.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
127 | 124 | #if TEST_STD_VER >= 14 |
128 | | - m.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
129 | | - cm.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 125 | + tm.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 126 | + ctm.equal_range(tkey); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
130 | 127 | #endif |
131 | 128 | } |
0 commit comments