Skip to content

Commit 3173147

Browse files
authored
Merge pull request #30 from iris-cpp/fix-potential-bug
Fix the semantics of `operator=(variant(rhs))` specified in [variant.assign]/2.5
2 parents 416b371 + fb00856 commit 3173147

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎include/iris/rvariant/rvariant.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
139139
if constexpr (std::is_nothrow_copy_constructible_v<T> || !std::is_nothrow_move_constructible_v<T>) {
140140
reset_construct<j>(rhs_alt); // A
141141
} else {
142-
auto tmp = rhs_alt;
142+
T tmp(rhs_alt);
143143
reset_construct<j>(std::move(tmp)); // B
144144
}
145145
}

‎test/rvariant/rvariant.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,24 @@ TEST_CASE("copy assignment")
10611061
CHECK(a.valueless_by_exception() == true);
10621062
}
10631063

1064+
{
1065+
// see https://github.com/microsoft/STL/issues/6085
1066+
struct S {
1067+
S() noexcept = default;
1068+
1069+
explicit S(S const&) noexcept(false) = default;
1070+
S(S&&) noexcept = default;
1071+
1072+
S& operator=(S const&) noexcept { return *this; }
1073+
S& operator=(S&&) noexcept = default;
1074+
};
1075+
1076+
iris::rvariant<int, S> a = 42;
1077+
iris::rvariant<int, S> b = S{};
1078+
a = b;
1079+
REQUIRE(a.index() == 1);
1080+
}
1081+
10641082
// NOLINTEND(modernize-use-equals-default)
10651083
}
10661084

0 commit comments

Comments
 (0)