aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-08-28 13:07:47 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2024-09-03 15:08:44 +0100
commitdee3c5c6ff9952204af3014383593e8d316250e4 (patch)
treec2f28ebde72efea7cd0f59b3200ea76e99de209e
parentefe6efb6f315c7f97be8a850e0a84ff7f6651d85 (diff)
downloadgcc-dee3c5c6ff9952204af3014383593e8d316250e4.zip
gcc-dee3c5c6ff9952204af3014383593e8d316250e4.tar.gz
gcc-dee3c5c6ff9952204af3014383593e8d316250e4.tar.bz2
libstdc++: Simplify std::any to fix -Wdeprecated-declarations warning
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.
-rw-r--r--libstdc++-v3/include/experimental/any2
-rw-r--r--libstdc++-v3/include/std/any2
-rw-r--r--libstdc++-v3/testsuite/20_util/any/layout.cc22
3 files changed, 24 insertions, 2 deletions
diff --git a/libstdc++-v3/include/experimental/any b/libstdc++-v3/include/experimental/any
index 27a7a14..3db30df 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<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>,
diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index e4709b1c..9ae29aa 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<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>,
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 0000000..5a7f4a8
--- /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 <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) );