diff --git a/src/entt/core/any.hpp b/src/entt/core/any.hpp index fda63c51b..7b7858c0d 100644 --- a/src/entt/core/any.hpp +++ b/src/entt/core/any.hpp @@ -1,6 +1,7 @@ #ifndef ENTT_CORE_ANY_HPP #define ENTT_CORE_ANY_HPP +#include #include #include #include @@ -49,10 +50,6 @@ class basic_any { using operation = internal::any_operation; using vtable_type = const void *(const operation, const basic_any &, const void *); - struct storage_type { - alignas(Align) std::byte data[Len + !Len]; - }; - template static constexpr bool in_situ = Len && alignof(Type) <= Align && sizeof(Type) <= Len && std::is_nothrow_move_constructible_v; @@ -62,7 +59,7 @@ class basic_any { const Type *elem = nullptr; if constexpr(in_situ) { - elem = (value.mode == any_policy::owner) ? reinterpret_cast(&value.storage) : static_cast(value.instance); + elem = (value.mode == any_policy::owner) ? reinterpret_cast(value.storage.data()) : static_cast(value.instance); } else { elem = static_cast(value.instance); } @@ -76,7 +73,7 @@ class basic_any { case operation::move: if constexpr(in_situ) { if(value.mode == any_policy::owner) { - return ::new(&static_cast(const_cast(other))->storage) Type{std::move(*const_cast(elem))}; + return ::new(static_cast(const_cast(other))->storage.data()) Type{std::move(*const_cast(elem))}; } } @@ -128,9 +125,9 @@ class basic_any { instance = (std::addressof(args), ...); } else if constexpr(in_situ>>) { if constexpr(std::is_aggregate_v>> && (sizeof...(Args) != 0u || !std::is_default_constructible_v>>)) { - ::new(&storage) std::remove_cv_t>{std::forward(args)...}; + ::new(storage.data()) std::remove_cv_t>{std::forward(args)...}; } else { - ::new(&storage) std::remove_cv_t>(std::forward(args)...); + ::new(storage.data()) std::remove_cv_t>(std::forward(args)...); } } else { if constexpr(std::is_aggregate_v>> && (sizeof...(Args) != 0u || !std::is_default_constructible_v>>)) { @@ -406,7 +403,7 @@ public: private: union { const void *instance; - storage_type storage; + alignas(Align) std::array storage; }; const type_info *info; vtable_type *vtable;