[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
This commit is contained in:
Nikolas Klauser 2022-12-11 02:10:31 +01:00
parent 5fb3a57ea7
commit 987f08fe22
17 changed files with 79 additions and 14 deletions

View File

@ -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:

View File

@ -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|"

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -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

View File

@ -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();

View File

@ -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\
{\

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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}}

View File

@ -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"

View File

@ -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}}

View File

@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
// type_traits
// aligned_union<size_t Len, class ...Types>

View File

@ -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;

View File

@ -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);