You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[libc++] Avoid using **this in error messages for expected monadic operations (#84840)
Instead of using **this in error messages for std::expected monadic
operations, use value(). As shown in LWG3969, **this can trigger
unintended ADL and while it's only an error message, we might as
well be ADL-correct there too.
Co-authored-by: Louis Dionne <[email protected]>
Copy file name to clipboardExpand all lines: libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -11,22 +11,22 @@
11
11
// Test the mandates
12
12
// template<class F> constexpr auto and_then(F&& f) &;
13
13
// Mandates:
14
-
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(**this)>>
14
+
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(value())>>
15
15
// U is a specialization of std::expected and std::is_same_v<U:error_type, E> is true
16
16
17
17
// template<class F> constexpr auto and_then(F&& f) const &;
18
18
// Mandates:
19
-
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(**this)>>
19
+
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(value())>>
20
20
// U is a specialization of std::expected and std::is_same_v<U:error_type, E> is true
21
21
22
22
// template<class F> constexpr auto and_then(F&& f) &&;
23
23
// Mandates:
24
-
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(**this)>>
24
+
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(value())>>
25
25
// U is a specialization of std::expected and std::is_same_v<U:error_type, E> is true
26
26
27
27
// template<class F> constexpr auto and_then(F&& f) const &&;
28
28
// Mandates:
29
-
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(**this)>>
29
+
// Let U be std::remove_cvref_t<std::invoke_result<F, decltype(value())>>
30
30
// U is a specialization of std::expected and std::is_same_v<U:error_type, E> is true
31
31
32
32
#include<expected>
@@ -52,7 +52,7 @@ void test() {
52
52
{
53
53
std::expected<int, int> f1(1);
54
54
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(**this) must be a specialization of std::expected}}
55
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
56
56
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
57
57
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
58
58
}
@@ -61,7 +61,7 @@ void test() {
61
61
{
62
62
std::expected<int, int> f1(1);
63
63
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(**this) must have the same error_type as this expected}}
64
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
65
65
}
66
66
}
67
67
@@ -71,7 +71,7 @@ void test() {
71
71
{
72
72
const std::expected<int, int> f1(1);
73
73
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(**this) must be a specialization of std::expected}}
74
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
75
75
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
76
76
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
77
77
}
@@ -80,7 +80,7 @@ void test() {
80
80
{
81
81
const std::expected<int, int> f1(1);
82
82
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(**this) must have the same error_type as this expected}}
83
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
84
84
85
85
}
86
86
}
@@ -91,7 +91,7 @@ void test() {
91
91
{
92
92
std::expected<int, int> f1(1);
93
93
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(**this)) must be a specialization of std::expected}}
94
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
95
95
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
96
96
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
97
97
}
@@ -100,7 +100,7 @@ void test() {
100
100
{
101
101
std::expected<int, int> f1(1);
102
102
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(**this)) must have the same error_type as this expected}}
103
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
104
104
}
105
105
}
106
106
@@ -110,7 +110,7 @@ void test() {
110
110
{
111
111
const std::expected<int, int> f1(1);
112
112
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(**this)) must be a specialization of std::expected}}
113
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
114
114
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
115
115
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
116
116
}
@@ -119,7 +119,7 @@ void test() {
119
119
{
120
120
const std::expected<int, int> f1(1);
121
121
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
-
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(**this)) must have the same error_type as this expected}}
122
+
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
0 commit comments