diff --git a/AK/Variant.h b/AK/Variant.h index f757e2a3acd..dae5cd7272c 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -210,7 +210,11 @@ public: template friend struct Variant; - Variant() = delete; + Variant() requires(!can_contain()) = delete; + Variant() requires(can_contain()) + : Variant(Empty()) + { + } #ifdef AK_HAS_CONDITIONALLY_TRIVIAL Variant(const Variant&) requires(!(IsCopyConstructible && ...)) = delete; diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp index 8175b695dab..f05c629022a 100644 --- a/Tests/AK/TestVariant.cpp +++ b/Tests/AK/TestVariant.cpp @@ -219,3 +219,10 @@ TEST_CASE(copy_assign) EXPECT_EQ(the_value.get(), "Hello, world!"); } } + +TEST_CASE(default_empty) +{ + Variant my_variant; + EXPECT(my_variant.has()); + EXPECT(!my_variant.has()); +}