// { dg-do compile { target c++23 } } #include void test_unexpected() { int i[2]{}; // std::unexpected is ill-formed if E is a non-object type, std::unexpected ref(i[0]); // { dg-error "here" } std::unexpected func(test_unexpected); // { dg-error "here" } // { dg-error "no matching function for call to" "" { target *-*-* } 0 } // { dg-error "invalidly declared function type" "" { target *-*-* } 0 } // an array type, std::unexpected array(i); // { dg-error "here" } // a specialization of std::unexpected, std::unexpected u(1); std::unexpected> nested(u); // { dg-error "here" } // // or a cv-qualified type. std::unexpected c_int(1); // { dg-error "here" } std::unexpected v_int(1); // { dg-error "here" } } void test_expected_value() { // std::expected is ill-formed if T is a reference type, std::expected ref(std::unexpect); // { dg-error "here" } // { dg-error "reference type" "" { target *-*-* } 0 } // a function type, std::expected func(std::unexpect); // { dg-error "here" } // { dg-error "returning a function" "" { target *-*-* } 0 } // // possibly cv-qualified types in_place_t, std::expected tag(std::unexpect); // { dg-error "here" } std::expected ctag(std::unexpect); // { dg-error "here" } // unexpect_t, std::expected utag(std::unexpect); // { dg-error "here" } std::expected cutag(std::unexpect); // { dg-error "here" } // or a specialization of unexpected. std::expected, int> unex(std::in_place, 1); // { dg-error "here" } std::expected, int> cunex(std::in_place, 1); // { dg-error "here" } } void test_expected_error() { // std::expected is ill-formed if std::unexpected would be // ill-formed. Test the same types as in test_unexpected(). std::expected ref; // { dg-error "here" } std::expected func; // { dg-error "here" } std::expected array; // { dg-error "here" } std::expected> nested; // { dg-error "here" } std::expected c_int; // { dg-error "here" } std::expected v_int; // { dg-error "here" } } // { dg-prune-output "static assertion failed" } // { dg-prune-output "function returning an array" }