Skip to content

Commit a5f9e46

Browse files
committed
[libcxx] add nodiscard test for monadic operations
1 parent 66e1dbc commit a5f9e46

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,13 @@ void test() {
122122
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
123123
}
124124
}
125+
126+
// Test nodiscard
127+
{
128+
const std::expected<int, int> f1(std::unexpected<int>(1));
129+
130+
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
131+
f1.and_then([](int&){ return 1; });
132+
}
125133
}
126134
// clang-format on

libcxx/test/libcxx/utilities/expected/expected.expected/or_else.mandates.verify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,13 @@ void test() {
121121
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
122122
}
123123
}
124+
125+
// Test nodiscard
126+
{
127+
const std::expected<int, int> f1(std::unexpected<int>(1));
128+
129+
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
130+
f1.or_else([](int&){ return 1; });
131+
}
124132
}
125133
// clang-format on

libcxx/test/libcxx/utilities/expected/expected.void/and_then.mandates.verify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,13 @@ void test() {
121121
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must have the same error_type as this expected}}
122122
}
123123
}
124+
125+
// Test nodiscard
126+
{
127+
const std::expected<int, int> f1(std::unexpected<int>(1));
128+
129+
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
130+
f1.and_then([](int&){ return 1; });
131+
}
124132
}
125133
// clang-format on

libcxx/test/libcxx/utilities/expected/expected.void/or_else.mandates.verify.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,14 @@ void test() {
117117
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f((void)std::move(error())) must have the same value_type as this expected}}
118118
}
119119
}
120+
121+
122+
// Test nodiscard
123+
{
124+
const std::expected<int, int> f1(std::unexpected<int>(1));
125+
126+
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
127+
f1.or_else([](int&){ return 1; });
128+
}
120129
}
121130
// clang-format on

0 commit comments

Comments
 (0)