We don't need to use std::aligned_storage in std::any. We just need a
POD type of the right size. The void* union member already ensures the
alignment will be correct. Avoiding std::aligned_storage means we don't
need to suppress a -Wdeprecated-declarations warning.
libstdc++-v3/ChangeLog:
* include/experimental/any (experimental::any::_Storage): Use
array of unsigned char instead of deprecated
std::aligned_storage.
* include/std/any (any::_Storage): Likewise.
* testsuite/20_util/any/layout.cc: New test.
_Storage& operator=(const _Storage&) = delete;
void* _M_ptr;
- aligned_storage<sizeof(_M_ptr), alignof(void*)>::type _M_buffer;
+ unsigned char _M_buffer[sizeof(_M_ptr)];
};
template<typename _Tp, typename _Safe = is_nothrow_move_constructible<_Tp>,
_Storage& operator=(const _Storage&) = delete;
void* _M_ptr;
- aligned_storage<sizeof(_M_ptr), alignof(void*)>::type _M_buffer;
+ unsigned char _M_buffer[sizeof(_M_ptr)];
};
template<typename _Tp, typename _Safe = is_nothrow_move_constructible<_Tp>,
--- /dev/null
+// { dg-options "-Wno-deprecated-declarations" }
+// { dg-do compile { target c++17 } }
+
+// Verify that r15-3419 did not change the layout of std::any
+
+#include <any>
+
+namespace test {
+ class any {
+ union Storage {
+ constexpr Storage() : ptr(nullptr) { }
+ void* ptr;
+ std::aligned_storage<sizeof(ptr), alignof(void*)>::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) );