[libcxx-commits] [libcxx] 987f08f - [libc++] Implement P1413R3 (Deprecate std::aligned_storage and std::aligned_union)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 21 06:08:33 PST 2023


Author: Nikolas Klauser
Date: 2023-01-21T15:08:27+01:00
New Revision: 987f08fe229c2d857b28f08b3b1ba149e1b16851

URL: https://github.com/llvm/llvm-project/commit/987f08fe229c2d857b28f08b3b1ba149e1b16851
DIFF: https://github.com/llvm/llvm-project/commit/987f08fe229c2d857b28f08b3b1ba149e1b16851.diff

LOG: [libc++] Implement P1413R3 (Deprecate std::aligned_storage and std::aligned_union)

There are no tests for the aliases because clang doesn't diagnose deprecated template aliases currently.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D127678

Added: 
    libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.depr.verify.cpp
    libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.depr.verify.cpp

Modified: 
    libcxx/docs/Status/Cxx2b.rst
    libcxx/docs/Status/Cxx2bPapers.csv
    libcxx/include/__config
    libcxx/include/__functional/function.h
    libcxx/include/__type_traits/aligned_storage.h
    libcxx/include/__type_traits/aligned_union.h
    libcxx/include/any
    libcxx/include/future
    libcxx/include/type_traits
    libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp
    libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp
    libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
    libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp
    libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/allocate.pass.cpp
    libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/deallocate.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/Status/Cxx2b.rst b/libcxx/docs/Status/Cxx2b.rst
index 41b790e8e07e..50d9a029a3e6 100644
--- a/libcxx/docs/Status/Cxx2b.rst
+++ b/libcxx/docs/Status/Cxx2b.rst
@@ -41,6 +41,8 @@ Paper Status
 
    .. [#note-P2273] P2273: ``make_unique_for_overwrite`` isn't done yet since `P1020` hasn't been implemented yet.
    .. [#note-P0533R9] P0533R9: ``isfinite``, ``isinf``, ``isnan`` and ``isnormal`` are implemented.
+   .. [#note-P1413R3] P1413R3: ``std::aligned_storage_t`` and ``std::aligned_union_t`` are marked deprecated, but
+      clang doesn't issue a diagnostic for deprecated using template declarations.
 
 .. _issues-status-cxx2b:
 

diff  --git a/libcxx/docs/Status/Cxx2bPapers.csv b/libcxx/docs/Status/Cxx2bPapers.csv
index 487936535f34..ce5e96d2f91f 100644
--- a/libcxx/docs/Status/Cxx2bPapers.csv
+++ b/libcxx/docs/Status/Cxx2bPapers.csv
@@ -42,7 +42,7 @@
 "`P0533R9 <https://wg21.link/P0533R9>`__","LWG","``constexpr`` for ``<cmath>`` and ``<cstdlib>``","February 2022","|In progress| [#note-P0533R9]_",""
 "`P0627R6 <https://wg21.link/P0627R6>`__","LWG","Function to mark unreachable code","February 2022","|Complete|","15.0"
 "`P1206R7 <https://wg21.link/P1206R7>`__","LWG","``ranges::to``: A function to convert any range to a container","February 2022","","","|ranges|"
-"`P1413R3 <https://wg21.link/P1413R3>`__","LWG","Deprecate ``std::aligned_storage`` and ``std::aligned_union``","February 2022","",""
+"`P1413R3 <https://wg21.link/P1413R3>`__","LWG","Deprecate ``std::aligned_storage`` and ``std::aligned_union``","February 2022","|Complete| [#note-P1413R3]_",""
 "`P2255R2 <https://wg21.link/P2255R2>`__","LWG","A type trait to detect reference binding to temporary","February 2022","",""
 "`P2273R3 <https://wg21.link/P2273R3>`__","LWG","Making ``std::unique_ptr`` constexpr","February 2022","|Partial| [#note-P2273]_","16.0"
 "`P2387R3 <https://wg21.link/P2387R3>`__","LWG","Pipe support for user-defined range adaptors","February 2022","","","|ranges|"

diff  --git a/libcxx/include/__config b/libcxx/include/__config
index a5d54d4e1872..b9203e640a3e 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -802,6 +802,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
 #    define _LIBCPP_DEPRECATED_IN_CXX20
 #  endif
 
+#if _LIBCPP_STD_VER >= 23
+#  define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
+#else
+#  define _LIBCPP_DEPRECATED_IN_CXX23
+#endif
+
 #  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
 #    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
 #  else

diff  --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index 8f34d0128bb6..ca79d334a028 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -382,7 +382,9 @@ template <class _Fp> class __value_func;
 
 template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
 {
+    _LIBCPP_SUPPRESS_DEPRECATED_PUSH
     typename aligned_storage<3 * sizeof(void*)>::type __buf_;
+    _LIBCPP_SUPPRESS_DEPRECATED_POP
 
     typedef __base<_Rp(_ArgTypes...)> __func;
     __func* __f_;
@@ -515,7 +517,9 @@ template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
             return;
         if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
         {
+            _LIBCPP_SUPPRESS_DEPRECATED_PUSH
             typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
+            _LIBCPP_SUPPRESS_DEPRECATED_POP
             __func* __t = __as_base(&__tempbuf);
             __f_->__clone(__t);
             __f_->destroy();

diff  --git a/libcxx/include/__type_traits/aligned_storage.h b/libcxx/include/__type_traits/aligned_storage.h
index a9f1244ed3cc..c564d582452d 100644
--- a/libcxx/include/__type_traits/aligned_storage.h
+++ b/libcxx/include/__type_traits/aligned_storage.h
@@ -83,7 +83,7 @@ struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
     : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
 
 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
-struct _LIBCPP_TEMPLATE_VIS aligned_storage
+struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage
 {
     typedef typename __find_pod<__all_types, _Align>::type _Aligner;
     union type
@@ -94,13 +94,17 @@ struct _LIBCPP_TEMPLATE_VIS aligned_storage
 };
 
 #if _LIBCPP_STD_VER > 11
+
+  _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
-    using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
+    using aligned_storage_t _LIBCPP_DEPRECATED_IN_CXX23 = typename aligned_storage<_Len, _Align>::type;
+  _LIBCPP_SUPPRESS_DEPRECATED_POP
+
 #endif
 
 #define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
 template <size_t _Len>\
-struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
+struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
 {\
     struct _ALIGNAS(n) type\
     {\

diff  --git a/libcxx/include/__type_traits/aligned_union.h b/libcxx/include/__type_traits/aligned_union.h
index 31eb9353a9e2..2c64130da307 100644
--- a/libcxx/include/__type_traits/aligned_union.h
+++ b/libcxx/include/__type_traits/aligned_union.h
@@ -37,7 +37,7 @@ struct __static_max<_I0, _I1, _In...>
 };
 
 template <size_t _Len, class _Type0, class ..._Types>
-struct aligned_union
+struct _LIBCPP_DEPRECATED_IN_CXX23 aligned_union
 {
     static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
                                                        _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
@@ -47,7 +47,8 @@ struct aligned_union
 };
 
 #if _LIBCPP_STD_VER > 11
-template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
+template <size_t _Len, class... _Types>
+using aligned_union_t _LIBCPP_DEPRECATED_IN_CXX23 = typename aligned_union<_Len, _Types...>::type;
 #endif
 
 _LIBCPP_END_NAMESPACE_STD

diff  --git a/libcxx/include/any b/libcxx/include/any
index ec5171ff714e..92cbc9a6c92d 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -138,7 +138,9 @@ add_pointer_t<_ValueType> any_cast(any *) _NOEXCEPT;
 
 namespace __any_imp
 {
+  _LIBCPP_SUPPRESS_DEPRECATED_PUSH
   using _Buffer = aligned_storage_t<3*sizeof(void*), alignment_of<void*>::value>;
+  _LIBCPP_SUPPRESS_DEPRECATED_POP
 
   template <class _Tp>
   using _IsSmallObject = integral_constant<bool

diff  --git a/libcxx/include/future b/libcxx/include/future
index dcacd7ad5374..2f14a471c458 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -625,7 +625,9 @@ class _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_HIDDEN __assoc_state
     : public __assoc_sub_state
 {
     typedef __assoc_sub_state base;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
     typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up;
+_LIBCPP_SUPPRESS_DEPRECATED_POP
 protected:
     _Up __value_;
 
@@ -1702,7 +1704,9 @@ class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_function<_Rp(_ArgTypes...)>
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_NO_CFI
     __base* __get_buf() { return (__base*)&__buf_; }
 
+    _LIBCPP_SUPPRESS_DEPRECATED_PUSH
     typename aligned_storage<3*sizeof(void*)>::type __buf_;
+    _LIBCPP_SUPPRESS_DEPRECATED_POP
     __base* __f_;
 
 public:
@@ -1835,7 +1839,9 @@ __packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f)
 {
     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
     {
+        _LIBCPP_SUPPRESS_DEPRECATED_PUSH
         typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
+        _LIBCPP_SUPPRESS_DEPRECATED_POP
         __base* __t = (__base*)&__tempbuf;
         __f_->__move_to(__t);
         __f_->destroy();

diff  --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index 757226f885cc..7646f5805980 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -158,8 +158,8 @@ namespace std
     // Alignment properties and transformations:
     template <class T> struct alignment_of;
     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
-        struct aligned_storage;
-    template <size_t Len, class... Types> struct aligned_union;
+        struct aligned_storage;                                 // deprecated in C++23
+    template <size_t Len, class... Types> struct aligned_union; // deprecated in C++23
     template <class T> struct remove_cvref; // C++20
 
     template <class T> struct decay;

diff  --git a/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp b/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp
index a33989e0d98d..297235efc48c 100644
--- a/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp
+++ b/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/allocate.pass.cpp
@@ -38,7 +38,7 @@ namespace ex = std::experimental::pmr;
 
 template <size_t S, size_t Align>
 void testForSizeAndAlign() {
-    using T = typename std::aligned_storage<S, Align>::type;
+    struct T { alignas(Align) char data[S]; };
     TestResource R;
     ex::polymorphic_allocator<T> a(&R);
 
@@ -54,7 +54,7 @@ void testForSizeAndAlign() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 template <size_t S>
 void testAllocForSizeThrows() {
-    using T = typename std::aligned_storage<S>::type;
+    struct T { char data[S]; };
     using Alloc = ex::polymorphic_allocator<T>;
     using Traits = std::allocator_traits<Alloc>;
     NullResource R;

diff  --git a/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp b/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp
index ec6059de39ad..0084d37a5083 100644
--- a/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp
+++ b/libcxx/test/std/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/deallocate.pass.cpp
@@ -36,7 +36,7 @@ namespace ex = std::experimental::pmr;
 
 template <size_t S, size_t Align>
 void testForSizeAndAlign() {
-    using T = typename std::aligned_storage<S, Align>::type;
+    struct T { alignas(Align) char data[S]; };
 
     TestResource R;
     ex::polymorphic_allocator<T> a(&R);

diff  --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.depr.verify.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.depr.verify.cpp
new file mode 100644
index 000000000000..d8fa38a107db
--- /dev/null
+++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.depr.verify.cpp
@@ -0,0 +1,14 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include <type_traits>
+
+std::aligned_storage<1, 1>::type s2; // expected-warning {{'aligned_storage<1, 1>' is deprecated}}
+std::aligned_storage<3, 1>::type s3; // expected-warning {{'aligned_storage<3, 1>' is deprecated}}

diff  --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
index 890d0d68eb48..35d116065b07 100644
--- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
@@ -13,6 +13,8 @@
 //  Issue 3034 added:
 //  The member typedef type shall be a trivial standard-layout type.
 
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
+
 #include <type_traits>
 #include <cstddef>       // for std::max_align_t
 #include "test_macros.h"

diff  --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.depr.verify.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.depr.verify.cpp
new file mode 100644
index 000000000000..f3445ef680c5
--- /dev/null
+++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.depr.verify.cpp
@@ -0,0 +1,14 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include <type_traits>
+
+std::aligned_union<1, int>::type s2; // expected-warning {{'aligned_union<1, int>' is deprecated}}
+std::aligned_union<3, char, char>::type s3; // expected-warning {{'aligned_union<3, char, char>' is deprecated}}

diff  --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp
index ff628450df25..73ca06532f08 100644
--- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
+
 // type_traits
 
 // aligned_union<size_t Len, class ...Types>

diff  --git a/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/allocate.pass.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/allocate.pass.cpp
index f044e7a66115..ece7594e8ff2 100644
--- a/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/allocate.pass.cpp
+++ b/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/allocate.pass.cpp
@@ -31,7 +31,10 @@
 
 template <size_t S, size_t Align>
 void testForSizeAndAlign() {
-  using T = typename std::aligned_storage<S, Align>::type;
+  struct T {
+    alignas(Align) std::byte buf[S];
+  };
+
   TestResource R;
   std::pmr::polymorphic_allocator<T> a(&R);
 
@@ -47,7 +50,10 @@ void testForSizeAndAlign() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 template <size_t S>
 void testAllocForSizeThrows() {
-  using T      = typename std::aligned_storage<S>::type;
+  struct T {
+    std::byte buf[S];
+  };
+
   using Alloc  = std::pmr::polymorphic_allocator<T>;
   using Traits = std::allocator_traits<Alloc>;
   NullResource R;

diff  --git a/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/deallocate.pass.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/deallocate.pass.cpp
index 7068c7553769..e7884c9b079f 100644
--- a/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/deallocate.pass.cpp
+++ b/libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/deallocate.pass.cpp
@@ -28,7 +28,9 @@
 
 template <size_t S, size_t Align>
 void testForSizeAndAlign() {
-  using T = typename std::aligned_storage<S, Align>::type;
+  struct T {
+    alignas(Align) std::byte buf[S];
+  };
 
   TestResource R;
   std::pmr::polymorphic_allocator<T> a(&R);


        


More information about the libcxx-commits mailing list