1515#include < expected>
1616#include < utility>
1717
18- struct LVal {
19- constexpr std::expected<int , int > operator ()(int &) { return 1 ; }
20- std::expected<int , int > operator ()(const int &) = delete;
21- std::expected<int , int > operator ()(int &&) = delete;
22- std::expected<int , int > operator ()(const int &&) = delete;
23- };
24-
25- struct CLVal {
26- std::expected<int , int > operator ()(int &) = delete;
27- constexpr std::expected<int , int > operator ()(const int &) { return 1 ; }
28- std::expected<int , int > operator ()(int &&) = delete;
29- std::expected<int , int > operator ()(const int &&) = delete;
30- };
31-
32- struct RVal {
33- std::expected<int , int > operator ()(int &) = delete;
34- std::expected<int , int > operator ()(const int &) = delete;
35- constexpr std::expected<int , int > operator ()(int &&) { return 1 ; }
36- std::expected<int , int > operator ()(const int &&) = delete;
37- };
38-
39- struct CRVal {
40- std::expected<int , int > operator ()(int &) = delete;
41- std::expected<int , int > operator ()(const int &) = delete;
42- std::expected<int , int > operator ()(int &&) = delete;
43- constexpr std::expected<int , int > operator ()(const int &&) { return 1 ; }
44- };
45-
4618void test () {
4719 // [expected.bad.void]
4820
@@ -56,8 +28,8 @@ void test() {
5628
5729 // [expected.bad]
5830
59- std::bad_expected_access<char > ex ( ' z' ) ;
60- const std::bad_expected_access<char > cEx ( ' z' ) ;
31+ std::bad_expected_access<char > ex{ ' z' } ;
32+ const std::bad_expected_access<char > cEx{ ' z' } ;
6133
6234 ex.error (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
6335 cEx.error (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -97,22 +69,22 @@ void test() {
9769 std::move (exp).error_or (82 );
9870
9971 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
100- exp.and_then (LVal{ });
72+ exp.and_then ([]( int &) { return std::expected< int , int >{ 94 }; });
10173 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
102- cExp.and_then (CLVal{ });
74+ cExp.and_then ([]( const int &) { return std::expected< int , int >{ 94 }; });
10375 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
104- std::move (exp).and_then (RVal{ });
76+ std::move (exp).and_then ([]( int &&) { return std::expected< int , int >{ 94 }; });
10577 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
106- std::move (cExp).and_then (CRVal{ });
78+ std::move (cExp).and_then ([]( const int &&) { return std::expected< int , int >{ 94 }; });
10779
10880 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
109- exp.or_else (LVal{ });
81+ exp.or_else ([]( int &) { return std::expected< int , int >{ 82 }; });
11082 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
111- cExp.or_else (CLVal{ });
83+ cExp.or_else ([]( const int &) { return std::expected< int , int >{ 82 }; });
11284 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
113- std::move (exp).or_else (RVal{ });
85+ std::move (exp).or_else ([]( int &&) { return std::expected< int , int >{ 82 }; });
11486 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
115- std::move (cExp).or_else (CRVal{ });
87+ std::move (cExp).or_else ([]( const int &&) { return std::expected< int , int >{ 82 }; });
11688
11789 // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
11890 exp.transform ([](int ) { return 94 ; });
0 commit comments