diff --git a/stl/inc/expected b/stl/inc/expected index a8399d7380..ced74191fa 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -306,11 +306,18 @@ public: template requires (!is_same_v, in_place_t> && !is_same_v, expected> && !_Is_specialization_v, unexpected> - && (!is_same_v, bool> || !_Is_specialization_v, expected>) + && (!is_same_v, bool> +#if defined(__clang__) || defined(__EDG__) // TRANSITION, DevCom-10655311 + || !_Is_specialization_v, expected> +#else // ^^^ no workaround / workaround vvv + || !_Is_specialization_v, _STD expected> +#endif // ^^^ workaround ^^^ + ) && is_constructible_v<_Ty, _Uty>) constexpr explicit(!is_convertible_v<_Uty, _Ty>) expected(_Uty&& _Other) noexcept(is_nothrow_constructible_v<_Ty, _Uty>) // strengthened - : _Value(_STD forward<_Uty>(_Other)), _Has_value(true) {} + : _Value(_STD forward<_Uty>(_Other)), _Has_value(true) { + } template requires is_constructible_v<_Err, const _UErr&> diff --git a/tests/std/tests/P0323R12_expected/test.cpp b/tests/std/tests/P0323R12_expected/test.cpp index 381e49bfa1..20b1753412 100644 --- a/tests/std/tests/P0323R12_expected/test.cpp +++ b/tests/std/tests/P0323R12_expected/test.cpp @@ -2317,6 +2317,30 @@ void test_lwg_3843() { static_assert(copyable>); static_assert(copyable>); +// Test workaround for DevCom-10655311: Class derived from std::expected can't be constructed with bool value type +template +class DerivedFromExpected : private expected { +public: + using expected::expected; + using expected::value; +}; + +static_assert(is_constructible_v, bool>); +static_assert(is_constructible_v, const bool&>); + +constexpr bool test_inherited_constructors() { + DerivedFromExpected wrapped_false_val(false); + assert(!wrapped_false_val.value()); + + constexpr bool true_val = true; + DerivedFromExpected wrapped_true_val(true_val); + assert(wrapped_true_val.value()); + + return true; +} + +static_assert(test_inherited_constructors()); + int main() { test_unexpected::test_all(); static_assert(test_unexpected::test_all()); @@ -2333,4 +2357,5 @@ int main() { test_reinit_regression(); test_lwg_3843(); + test_inherited_constructors(); }