diff --git a/libstdc++-v3/include/experimental/any b/libstdc++-v3/include/experimental/any index 27a7a146e53..3db30df5c75 100644 --- a/libstdc++-v3/include/experimental/any +++ b/libstdc++-v3/include/experimental/any @@ -102,7 +102,7 @@ inline namespace fundamentals_v1 _Storage& operator=(const _Storage&) = delete; void* _M_ptr; - aligned_storage::type _M_buffer; + unsigned char _M_buffer[sizeof(_M_ptr)]; }; template, diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any index e4709b1ce04..9ae29aab99f 100644 --- a/libstdc++-v3/include/std/any +++ b/libstdc++-v3/include/std/any @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Storage& operator=(const _Storage&) = delete; void* _M_ptr; - aligned_storage::type _M_buffer; + unsigned char _M_buffer[sizeof(_M_ptr)]; }; template, diff --git a/libstdc++-v3/testsuite/20_util/any/layout.cc b/libstdc++-v3/testsuite/20_util/any/layout.cc new file mode 100644 index 00000000000..5a7f4a8a280 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/any/layout.cc @@ -0,0 +1,22 @@ +// { dg-options "-Wno-deprecated-declarations" } +// { dg-do compile { target c++17 } } + +// Verify that r15-3419 did not change the layout of std::any + +#include + +namespace test { + class any { + union Storage { + constexpr Storage() : ptr(nullptr) { } + void* ptr; + std::aligned_storage::type buffer; + }; + + void (*manager)(int, const any*, void*); + Storage storage; + }; +} + +static_assert( sizeof(std::any) == sizeof(test::any) ); +static_assert( alignof(std::any) == alignof(test::any) );