Skip to content

Commit 25a3cd7

Browse files
committed
[libcxx] fix std::expected tests
1 parent c71ba32 commit 25a3cd7

File tree

7 files changed

+60
-59
lines changed

7 files changed

+60
-59
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// U is a specialization of std::expected and std::is_same_v<U:error_type, E> is true
3131

3232
#include <expected>
33+
#include <tuple>
3334
#include <utility>
3435

3536
struct NotSameAsInt {};
@@ -51,7 +52,7 @@ void test() {
5152
// U is not a specialization of std::expected
5253
{
5354
std::expected<int, int> f1(1);
54-
(void)f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &)>' requested here}}
55+
std::ignore = f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &)>' requested here}}
5556
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
5657
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
5758
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -60,7 +61,7 @@ void test() {
6061
// !std::is_same_v<U:error_type, E>
6162
{
6263
std::expected<int, int> f1(1);
63-
(void)f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &)>' requested here}}
64+
std::ignore = f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &)>' requested here}}
6465
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
6566
}
6667
}
@@ -70,7 +71,7 @@ void test() {
7071
// U is not a specialization of std::expected
7172
{
7273
const std::expected<int, int> f1(1);
73-
(void)f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &)>' requested here}}
74+
std::ignore = f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &)>' requested here}}
7475
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
7576
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
7677
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -79,7 +80,7 @@ void test() {
7980
// !std::is_same_v<U:error_type, E>
8081
{
8182
const std::expected<int, int> f1(1);
82-
(void)f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &)>' requested here}}
83+
std::ignore = f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &)>' requested here}}
8384
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
8485

8586
}
@@ -90,7 +91,7 @@ void test() {
9091
// U is not a specialization of std::expected
9192
{
9293
std::expected<int, int> f1(1);
93-
(void)std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &&)>' requested here}}
94+
std::ignore = std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &&)>' requested here}}
9495
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
9596
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
9697
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -99,7 +100,7 @@ void test() {
99100
// !std::is_same_v<U:error_type, E>
100101
{
101102
std::expected<int, int> f1(1);
102-
(void)std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &&)>' requested here}}
103+
std::ignore = std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &&)>' requested here}}
103104
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
104105
}
105106
}
@@ -109,7 +110,7 @@ void test() {
109110
// U is not a specialization of std::expected
110111
{
111112
const std::expected<int, int> f1(1);
112-
(void)std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &&)>' requested here}}
113+
std::ignore = std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &&)>' requested here}}
113114
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
114115
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
115116
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -118,7 +119,7 @@ void test() {
118119
// !std::is_same_v<U:error_type, E>
119120
{
120121
const std::expected<int, int> f1(1);
121-
(void)std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &&)>' requested here}}
122+
std::ignore = std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &&)>' requested here}}
122123
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
123124
}
124125
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ std::expected<void, int> returns_expected_void() {
2323
}
2424

2525
void test() {
26-
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
27-
returns_expected();
28-
29-
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
30-
returns_expected_void();
26+
returns_expected(); // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
28+
returns_expected_void(); // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
3129
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// G is a specialization of std::expected and std::is_same_v<G:value_type, T> is true
3131

3232
#include <expected>
33+
#include <tuple>
3334
#include <utility>
3435

3536
struct NotSameAsInt {};
@@ -51,7 +52,7 @@ void test() {
5152
// G is not a specialization of std::expected
5253
{
5354
std::expected<int, int> f1(std::unexpected<int>(1));
54-
(void)f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &)>' requested here}}
55+
std::ignore = f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &)>' requested here}}
5556
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
5657
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
5758
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -60,7 +61,7 @@ void test() {
6061
// !std::is_same_v<G:value_type, T>
6162
{
6263
std::expected<int, int> f1(std::unexpected<int>(1));
63-
(void)f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
64+
std::ignore = f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
6465
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
6566
}
6667
}
@@ -70,7 +71,7 @@ void test() {
7071
// G is not a specialization of std::expected
7172
{
7273
const std::expected<int, int> f1(std::unexpected<int>(1));
73-
(void)f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &)>' requested here}}
74+
std::ignore = f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &)>' requested here}}
7475
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
7576
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
7677
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -79,7 +80,7 @@ void test() {
7980
// !std::is_same_v<G:value_type, T>
8081
{
8182
const std::expected<int, int> f1(std::unexpected<int>(1));
82-
(void)f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
83+
std::ignore = f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
8384
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
8485
}
8586
}
@@ -89,7 +90,7 @@ void test() {
8990
// G is not a specialization of std::expected
9091
{
9192
std::expected<int, int> f1(std::unexpected<int>(1));
92-
(void)std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &&)>' requested here}}
93+
std::ignore = std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &&)>' requested here}}
9394
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
9495
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
9596
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -98,7 +99,7 @@ void test() {
9899
// !std::is_same_v<G:value_type, T>
99100
{
100101
std::expected<int, int> f1(std::unexpected<int>(1));
101-
(void)std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
102+
std::ignore = std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
102103
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
103104
}
104105
}
@@ -108,7 +109,7 @@ void test() {
108109
// G is not a specialization of std::expected
109110
{
110111
const std::expected<int, int> f1(std::unexpected<int>(1));
111-
(void)std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &&)>' requested here}}
112+
std::ignore = std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &&)>' requested here}}
112113
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
113114
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
114115
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@@ -117,7 +118,7 @@ void test() {
117118
// !std::is_same_v<G:value_type, T>
118119
{
119120
const std::expected<int, int> f1(std::unexpected<int>(1));
120-
(void)std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
121+
std::ignore = std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
121122
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
122123
}
123124
}
@@ -126,8 +127,7 @@ void test() {
126127
{
127128
const std::expected<int, int> f1(std::unexpected<int>(1));
128129

129-
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
130-
f1.or_else([](int&){ return 1; });
130+
f1.or_else([](int&){ return 1; }); // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
131131
}
132132
}
133133
// clang-format on

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// G g(invoke(std::forward<F>(f), std::move(error()))); is well-formed.
3939

4040
#include <expected>
41+
#include <tuple>
4142
#include <utility>
4243

4344
static int val;
@@ -58,12 +59,12 @@ void test() {
5859
// Test & overload
5960
{
6061
std::expected<int, int> e;
61-
e.transform_error(return_unexpected<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
62+
std::ignore = e.transform_error(return_unexpected<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
6263
// expected-error-re@*:* 0-1 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
6364
// expected-error-re@*:* {{static assertion failed {{.*}}[expected.object.general] A program that instantiates the definition of template expected<T, E> for {{.*}} is ill-formed.}}
6465
// expected-error-re@*:* 0-1 {{union member {{.*}} has reference type {{.*}}}}
6566

66-
e.transform_error(return_no_object<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
67+
std::ignore = e.transform_error(return_no_object<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
6768
// expected-error-re@*:* 0-1 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
6869
// expected-error-re@*:* {{static assertion failed {{.*}}[expected.object.general] A program that instantiates the definition of template expected<T, E> for {{.*}} is ill-formed.}}
6970
// expected-warning-re@*:* 0-1 {{union member {{.*}} has reference type {{.*}}, which is a Microsoft extension}}
@@ -72,27 +73,27 @@ void test() {
7273
// Test const& overload
7374
{
7475
const std::expected<int, int> e;
75-
e.transform_error(return_unexpected<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
76+
std::ignore = e.transform_error(return_unexpected<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
7677
// expected-error-re@*:* 0-2 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
77-
e.transform_error(return_no_object<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
78+
std::ignore = e.transform_error(return_no_object<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
7879
// expected-error-re@*:* 0-2 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
7980
}
8081

8182
// Test && overload
8283
{
8384
std::expected<int, int> e;
84-
std::move(e).transform_error(return_unexpected<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
85+
std::ignore = std::move(e).transform_error(return_unexpected<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
8586
// expected-error-re@*:* 0-2 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
86-
std::move(e).transform_error(return_no_object<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
87+
std::ignore = std::move(e).transform_error(return_no_object<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
8788
// expected-error-re@*:* 0-2 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
8889
}
8990

9091
// Test const&& overload
9192
{
9293
const std::expected<int, int> e;
93-
std::move(e).transform_error(return_unexpected<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
94+
std::ignore = std::move(e).transform_error(return_unexpected<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
9495
// expected-error-re@*:* 0-2 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
95-
std::move(e).transform_error(return_no_object<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
96+
std::ignore = std::move(e).transform_error(return_no_object<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
9697
// expected-error-re@*:* 0-2 {{{{(excess elements in struct initializer|no matching constructor for initialization of)}}{{.*}}}}
9798
}
9899
}

0 commit comments

Comments
 (0)