Skip to content

Commit fcd651d

Browse files
committed
Simplified tests
1 parent 5fb98f3 commit fcd651d

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

libcxx/test/libcxx/utilities/optional/nodiscard.verify.cpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,15 @@
1818

1919
#include "test_macros.h"
2020

21-
struct LVal {
22-
constexpr std::optional<int> operator()(int&) { return 1; }
23-
std::optional<int> operator()(const int&) = delete;
24-
std::optional<int> operator()(int&&) = delete;
25-
std::optional<int> operator()(const int&&) = delete;
26-
};
27-
28-
struct CLVal {
29-
std::optional<int> operator()(int&) = delete;
30-
constexpr std::optional<int> operator()(const int&) { return 1; }
31-
std::optional<int> operator()(int&&) = delete;
32-
std::optional<int> operator()(const int&&) = delete;
33-
};
34-
35-
struct RVal {
36-
std::optional<int> operator()(int&) = delete;
37-
std::optional<int> operator()(const int&) = delete;
38-
constexpr std::optional<int> operator()(int&&) { return 1; }
39-
std::optional<int> operator()(const int&&) = delete;
40-
};
41-
42-
struct CRVal {
43-
std::optional<int> operator()(int&) = delete;
44-
std::optional<int> operator()(const int&) = delete;
45-
std::optional<int> operator()(int&&) = delete;
46-
constexpr std::optional<int> operator()(const int&&) { return 1; }
47-
};
48-
4921
void test() {
22+
// [optional.bad.access]
23+
5024
std::bad_optional_access ex;
5125

5226
ex.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
5327

28+
// [optional.optional]
29+
5430
std::optional<int> opt;
5531
const std::optional<int> cOpt;
5632

@@ -84,29 +60,31 @@ void test() {
8460

8561
#if TEST_STD_VER >= 23
8662
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
87-
opt.and_then(LVal{});
63+
opt.and_then([](int&) { return std::optional<int>{94}; });
8864
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
89-
cOpt.and_then(CLVal{});
65+
cOpt.and_then([](const int&) { return std::optional<int>{94}; });
9066
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
91-
std::move(opt).and_then(RVal{});
67+
std::move(opt).and_then([](int&&) { return std::optional<int>{94}; });
9268
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
93-
std::move(cOpt).and_then(CRVal{});
69+
std::move(cOpt).and_then([](const int&&) { return std::optional<int>{94}; });
9470

9571
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
96-
opt.transform(LVal{});
72+
opt.transform([](int&) { return std::optional<int>{94}; });
9773
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
98-
cOpt.transform(CLVal{});
74+
cOpt.transform([](const int&) { return std::optional<int>{94}; });
9975
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
100-
std::move(opt).transform(RVal{});
76+
std::move(opt).transform([](int&&) { return std::optional<int>{94}; });
10177
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
102-
std::move(cOpt).transform(CRVal{});
78+
std::move(cOpt).transform([](const int&&) { return std::optional<int>{94}; });
10379

10480
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
10581
opt.or_else([] { return std::optional<int>{82}; });
10682
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
10783
std::move(opt).or_else([] { return std::optional<int>{82}; });
10884
#endif // TEST_STD_VER >= 23
10985

86+
// [optional.optional.ref]
87+
11088
#if TEST_STD_VER >= 26
11189
int z = 94;
11290
std::optional<int&> optRef{z};
@@ -143,13 +121,17 @@ void test() {
143121
std::move(optRef).or_else([] { return std::optional<int&>{}; });
144122
#endif // TEST_STD_VER >= 26
145123

124+
// [optional.specalg]
125+
146126
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
147127
std::make_optional(82);
148128
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
149129
std::make_optional<int>('h');
150130
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
151131
std::make_optional<std::string>({'z', 'm', 't'});
152132

133+
// [optional.hash]
134+
153135
std::hash<std::optional<int>> hash;
154136

155137
hash(opt); //expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

0 commit comments

Comments
 (0)