Skip to content

Commit e7bc34c

Browse files
authored
Merge pull request #27 from ComixHe/lwg-4222
implement LWG-4222
2 parents f832eaa + e875e3e commit e7bc34c

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Implemented LWG Issues:
2323
- [x] [LWG-3877](https://wg21.link/lwg3877) incorrect constraints on const-qualified monadic overloads for `std::expected`
2424
- [x] [LWG-3886](https://wg21.link/lwg3886) Monad mo' problems
2525
- [x] [LWG-4031](https://wg21.link/lwg4031) `bad_expected_access<void>` member functions should be noexcept
26+
- [x] [LWG-4222](https://wg21.link/lwg4222) `expected` constructor from a single value missing a constraint
2627

2728
Enhancements:
2829

include/zeus/expected.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ using enable_forward_t = std::enable_if_t<
291291
!std::is_same_v<expected<T, E>, expected_detail::remove_cvref_t<U>> && //
292292
!expected_detail::is_specialization_v<expected_detail::remove_cvref_t<U>, unexpected> && //
293293
(!std::is_same_v<std::remove_cv_t<T>, bool> || // LWG-3836
294-
!expected_detail::is_specialization_v<expected_detail::remove_cvref_t<U>, expected>) //
294+
!expected_detail::is_specialization_v<expected_detail::remove_cvref_t<U>, expected>) && //
295+
!std::is_same_v<expected_detail::remove_cvref_t<U>, unexpect_t> // LWG-4222
295296
>;
296297

297298
template<class T, class E, class U, class G, class UF, class GF>

tests/test_expected/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(SOURCES
77
equality_tests.cpp
88
lwg_3886_tests.cpp
99
lwg_4031_tests.cpp
10+
lwg_4222_tests.cpp
1011
)
1112

1213
find_package(Catch2 3 REQUIRED)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <catch2/catch_all.hpp>
2+
3+
#include <zeus/expected.hpp>
4+
5+
using namespace zeus;
6+
7+
namespace
8+
{
9+
10+
struct ConstructibleFromUnexpect
11+
{
12+
ConstructibleFromUnexpect() = default;
13+
explicit ConstructibleFromUnexpect([[maybe_unused]] unexpect_t ut) {}
14+
};
15+
16+
} // namespace
17+
18+
TEST_CASE("expected<T, E>(unexpect) is not ambiguous when T is constructible from unexpect_t", "[LWG-4222]")
19+
{
20+
expected<ConstructibleFromUnexpect, int> e(unexpect);
21+
CHECK_FALSE(e.has_value());
22+
CHECK(e.error() == int {});
23+
}
24+
25+
TEST_CASE("expected<T, E>(unexpect, args) still works when T is constructible from unexpect_t", "[LWG-4222]")
26+
{
27+
expected<ConstructibleFromUnexpect, int> e(unexpect, 42);
28+
CHECK_FALSE(e.has_value());
29+
CHECK(e.error() == 42);
30+
}

0 commit comments

Comments
 (0)