AK: Fix rvalue Variant downcast to variant aliases

Pass the required TypeWrapper through the rvalue downcast<Variant<...>>
path, matching the existing const& overload.
This commit is contained in:
Shannon Booth 2026-05-29 21:47:42 +02:00 committed by Shannon Booth
parent ae2783e705
commit de4b665298
2 changed files with 6 additions and 1 deletions

View file

@ -430,7 +430,7 @@ public:
decltype(auto) downcast() && decltype(auto) downcast() &&
{ {
if constexpr (sizeof...(NewTs) == 1 && (IsSpecializationOf<NewTs, Variant> && ...)) { if constexpr (sizeof...(NewTs) == 1 && (IsSpecializationOf<NewTs, Variant> && ...)) {
return move(*this).template downcast_variant<NewTs...>(); return move(*this).downcast_variant(TypeWrapper<NewTs...> {});
} else { } else {
Variant<NewTs...> instance { Variant<NewTs...>::invalid_index, Detail::VariantConstructTag {} }; Variant<NewTs...> instance { Variant<NewTs...>::invalid_index, Detail::VariantConstructTag {} };
visit([&](auto& value) { visit([&](auto& value) {

View file

@ -132,6 +132,11 @@ TEST_CASE(as)
EXPECT(one_integer_to_rule_them_all.has<i8>()); EXPECT(one_integer_to_rule_them_all.has<i8>());
EXPECT_EQ(fake_integer.get<i8>(), 60); EXPECT_EQ(fake_integer.get<i8>(), 60);
EXPECT_EQ(one_integer_to_rule_them_all.get<i8>(), 60); EXPECT_EQ(one_integer_to_rule_them_all.get<i8>(), 60);
using OptionalFancyType = Variant<i8, i16, Empty>;
auto definitely_fancy = OptionalFancyType { static_cast<i16>(12) }.downcast<SomeFancyType>();
EXPECT(definitely_fancy.has<i16>());
EXPECT_EQ(definitely_fancy.get<i16>(), 12);
} }
TEST_CASE(moved_from_state) TEST_CASE(moved_from_state)