File tree Expand file tree Collapse file tree 4 files changed +33
-0
lines changed
libcxx/test/libcxx/utilities/expected Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments