diff --git a/src/entt/core/any.hpp b/src/entt/core/any.hpp index 8f1e3f377..bde585d46 100644 --- a/src/entt/core/any.hpp +++ b/src/entt/core/any.hpp @@ -28,7 +28,7 @@ class basic_any { using vtable_type = const void *(const operation, const basic_any &, const void *); template - static constexpr bool in_situ = Len && sizeof(Type) <= sizeof(storage_type) && std::is_nothrow_move_constructible_v; + static constexpr bool in_situ = Len && alignof(Type) <= alignof(storage_type) && sizeof(Type) <= sizeof(storage_type) && std::is_nothrow_move_constructible_v; template [[nodiscard]] static bool compare(const void *lhs, const void *rhs) { diff --git a/test/entt/core/any.cpp b/test/entt/core/any.cpp index 566247bce..f4453c7b2 100644 --- a/test/entt/core/any.cpp +++ b/test/entt/core/any.cpp @@ -34,6 +34,8 @@ struct not_copyable { double payload[Sz]; }; +struct alignas(64u) over_aligned {}; + TEST(Any, SBO) { entt::any any{'c'}; @@ -884,3 +886,10 @@ TEST(Any, SBOVsZeroedSBOSize) { ASSERT_EQ(valid, same.data()); } + +TEST(Any, Alignment) { + static constexpr auto alignment = alignof(over_aligned); + entt::basic_any target[2] = { over_aligned{}, over_aligned{} }; + ASSERT_TRUE((reinterpret_cast(entt::any_cast(&target[0u])) % alignment) == 0u); + ASSERT_TRUE((reinterpret_cast(entt::any_cast(&target[1u])) % alignment) == 0u); +}