Skip to content

Commit 358bd94

Browse files
committed
Fix
1 parent fb4daf7 commit 358bd94

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,29 @@
1414

1515
#include "test_macros.h"
1616

17+
#if TEST_STD_VER >= 14
1718
template <typename T>
1819
struct TransparentKey {
19-
T t;
20-
21-
constexpr explicit operator T() const { return t; }
20+
explicit operator T() const;
2221
};
2322

2423
struct TransparentCompare {
2524
using is_transparent = void; // This makes the comparator transparent
2625

2726
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;
3128

3229
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;
3631

3732
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;
4134
};
35+
#endif
4236

4337
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;
4640

4741
m.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
4842
cm.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -92,40 +86,43 @@ void test() {
9286
m.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
9387
cm.find(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
9488
#if TEST_STD_VER >= 14
89+
std::map<int, int, TransparentCompare> tm;
90+
const std::map<int, int, TransparentCompare> ctm{};
91+
9592
TransparentKey<int> tkey;
9693

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}}
9996
#endif
10097

10198
m.count(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
10299
#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}}
104101
#endif
105102

106103
#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}}
109106
#endif
110107

111108
m.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
112109
cm.lower_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
113110
#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}}
116113
#endif
117114

118115
m.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
119116
cm.upper_bound(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
120117
#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}}
123120
#endif
124121

125122
m.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
126123
cm.equal_range(key); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
127124
#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}}
130127
#endif
131128
}

0 commit comments

Comments
 (0)