Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P1413R3 Deprecate aligned_storage & aligned_union #2583

Merged
merged 16 commits into from
May 17, 2022
2 changes: 1 addition & 1 deletion stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct _Optimistic_temporary_buffer { // temporary storage with _alloca-like att

_Ty* _Data; // points to heap memory iff _Capacity > _Optimistic_count
ptrdiff_t _Capacity;
aligned_union_t<0, _Ty> _Stack_space[_Optimistic_count];
typename _Aligned_storage<sizeof(_Ty), alignof(_Ty)>::type _Stack_space[_Optimistic_count];
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
};

#ifdef __cpp_lib_concepts
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/condition_variable
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public:
private:
shared_ptr<mutex> _Myptr;

aligned_storage_t<_Cnd_internal_imp_size, _Cnd_internal_imp_alignment> _Cnd_storage;
typename _Aligned_storage<_Cnd_internal_imp_size, _Cnd_internal_imp_alignment>::type _Cnd_storage;

_NODISCARD _Cnd_t _Mycnd() noexcept { // get pointer to _Cnd_internal_imp_t inside _Cnd_storage
return reinterpret_cast<_Cnd_t>(&_Cnd_storage);
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private:
friend condition_variable;
friend condition_variable_any;

aligned_storage_t<_Mtx_internal_imp_size, _Mtx_internal_imp_alignment> _Mtx_storage;
typename _Aligned_storage<_Mtx_internal_imp_size, _Mtx_internal_imp_alignment>::type _Mtx_storage;

_Mtx_t _Mymtx() noexcept { // get pointer to _Mtx_internal_imp_t inside _Mtx_storage
return reinterpret_cast<_Mtx_t>(&_Mtx_storage);
Expand Down Expand Up @@ -698,7 +698,7 @@ public:
}

private:
aligned_storage_t<_Cnd_internal_imp_size, _Cnd_internal_imp_alignment> _Cnd_storage;
typename _Aligned_storage<_Cnd_internal_imp_size, _Cnd_internal_imp_alignment>::type _Cnd_storage;

_Cnd_t _Mycnd() noexcept { // get pointer to _Cnd_internal_imp_t inside _Cnd_storage
return reinterpret_cast<_Cnd_t>(&_Cnd_storage);
Expand Down
15 changes: 12 additions & 3 deletions stl/inc/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,15 @@ struct _Aligned<_Len, _Align, char, false> {
};

template <size_t _Len, size_t _Align = alignof(max_align_t)>
struct aligned_storage { // define type with size _Len and alignment _Align
struct _CXX23_DEPRECATE_ALIGNED_STORAGE aligned_storage { // define type with size _Len and alignment _Align
using _Next = char;
static constexpr bool _Fits = _Align <= alignof(_Next);
using type = typename _Aligned<_Len, _Align, _Next, _Fits>::type;
};

// TRANSITION, ABI: Internal non-deprecated version to avoid ABI changes due to deprecation
template <size_t _Len, size_t _Align = alignof(max_align_t)>
struct _Aligned_storage { // define type with size _Len and alignment _Align
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
using _Next = char;
static constexpr bool _Fits = _Align <= alignof(_Next);
using type = typename _Aligned<_Len, _Align, _Next, _Fits>::type;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1046,11 +1054,12 @@ struct _Maximum<_First, _Second, _Rest...> : _Maximum<(_First < _Second ? _Secon
};

StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
template <size_t _Len, class... _Types>
struct aligned_union { // define type with size at least _Len, for storing anything in _Types
struct _CXX23_DEPRECATE_ALIGNED_UNION aligned_union { // define type with size at least _Len, for storing anything in
// _Types
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
static constexpr size_t _Max_len = _Maximum<_Len, sizeof(_Types)...>::value; // NOT sizeof...(_Types)
static constexpr size_t alignment_value = _Maximum<alignof(_Types)...>::value;

using type = aligned_storage_t<_Max_len, alignment_value>;
using type = typename _Aligned_storage<_Max_len, alignment_value>::type;
};

template <size_t _Len, class... _Types>
Expand Down
3 changes: 2 additions & 1 deletion stl/inc/xnode_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class _Node_handle : public _Base<_Node_handle<_Node, _Alloc, _Base, _Types...>,
using _Nodeptr = typename _Alnode_traits::pointer;

_Nodeptr _Ptr{};
aligned_union_t<0, _Alloc> _Alloc_storage; // Invariant: contains a live _Alloc iff _Ptr != nullptr
typename _Aligned_storage<sizeof(_Alloc), alignof(_Alloc)>::type
_Alloc_storage; // Invariant: contains a live _Alloc iff _Ptr != nullptr
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

void _Clear() noexcept { // destroy any contained node and return to the empty state
if (_Ptr != nullptr) {
Expand Down
27 changes: 26 additions & 1 deletion stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
// P1132R7 out_ptr(), inout_ptr()
// P1147R1 Printing volatile Pointers
// P1272R4 byteswap()
// P1413R3 Deprecate aligned_storage And aligned_union
// P1425R4 Iterator Pair Constructors For stack And queue
// P1659R3 ranges::starts_with, ranges::ends_with
// P1679R3 contains() For basic_string/basic_string_view
Expand Down Expand Up @@ -1105,7 +1106,31 @@
#define _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
#endif // ^^^ warning disabled ^^^

// next warning number: STL4034
#if _HAS_CXX23 && !defined(_SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING) \
&& !defined(_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS)
#define _CXX23_DEPRECATE_ALIGNED_STORAGE \
[[deprecated("warning STL4034: " \
"std::aligned_storage is deprecated in C++23 by P1413R3. " \
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
"Prefer alignas(T) std::byte t_buff[sizeof(T)]." \
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
"You can define _SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING " \
"or _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS to acknowledge that you have received this warning.")]]
#else // ^^^ warning enabled / warning disabled vvv
#define _CXX23_DEPRECATE_ALIGNED_STORAGE
#endif // ^^^ warning disabled ^^^

#if _HAS_CXX23 && !defined(_SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING) \
&& !defined(_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS)
#define _CXX23_DEPRECATE_ALIGNED_UNION \
[[deprecated("warning STL4035: " \
"std::aligned_union is deprecated in C++23 by P1413R3. " \
"Prefer alignas(Ts...) std::byte t_buff[std::max({sizeof(Ts)...})]." \
"You can define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING " \
"or _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS to acknowledge that you have received this warning.")]]
#else // ^^^ warning enabled / warning disabled vvv
#define _CXX23_DEPRECATE_ALIGNED_UNION
#endif // ^^^ warning disabled ^^^

// next warning number: STL4036

// P0619R4 Removing C++17-Deprecated Features
#ifndef _HAS_FEATURES_REMOVED_IN_CXX20
Expand Down
5 changes: 2 additions & 3 deletions stl/src/cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
#include "primitives.hpp"

struct _Cnd_internal_imp_t { // condition variable implementation for ConcRT
std::aligned_storage_t<Concurrency::details::stl_condition_variable_max_size,
Concurrency::details::stl_condition_variable_max_alignment>
cv;
typename std::_Aligned_storage<Concurrency::details::stl_condition_variable_max_size,
Concurrency::details::stl_condition_variable_max_alignment>::type cv;

[[nodiscard]] Concurrency::details::stl_condition_variable_interface* _get_cv() noexcept {
// get pointer to implementation
Expand Down
5 changes: 2 additions & 3 deletions stl/src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ extern "C" _CRTIMP2 void __cdecl __set_stl_sync_api_mode(__stl_sync_api_modes_en

struct _Mtx_internal_imp_t { // ConcRT mutex
int type;
std::aligned_storage_t<Concurrency::details::stl_critical_section_max_size,
Concurrency::details::stl_critical_section_max_alignment>
cs;
typename std::_Aligned_storage<Concurrency::details::stl_critical_section_max_size,
Concurrency::details::stl_critical_section_max_alignment>::type cs;
long thread_id;
int count;
Concurrency::details::stl_critical_section_interface* _get_cs() { // get pointer to implementation
Expand Down
10 changes: 5 additions & 5 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ std/containers/unord/unord.set/max_size.pass.cpp FAIL
std/utilities/tuple/tuple.tuple/tuple.apply/apply_large_arity.pass.cpp SKIPPED
std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp SKIPPED

# Deprecation is a mess. We disable all deprecations in msvc_stdlib_force_include.hpp to allow libc++ tests for
# deprecated features to pass, which breaks when libc++ deprecates the feature and adds two tests that (1) pass
# with deprecation suppressed, and (2) fail without deprecation suppression. We should instead translate libc++
# un-deprecation macros to STL un-deprecation macros in the force-include header, and just skip tests when we
# deprecate before they do.
# Deprecation is a mess. We disable all deprecations in llvm-project/libcxx/test/support/msvc_stdlib_force_include.h
# (external to this repo) to allow libc++ tests for deprecated features to pass, which breaks when libc++ deprecates
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
# the feature and adds two tests that (1) pass with deprecation suppressed, and (2) fail without deprecation suppression.
# We should instead translate libc++ un-deprecation macros to STL un-deprecation macros in the force-include header,
# and just skip tests when we deprecate before they do.
std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.deprecated.fail.cpp FAIL


Expand Down
10 changes: 5 additions & 5 deletions tests/libcxx/skipped_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ containers\unord\unord.set\max_size.pass.cpp
utilities\tuple\tuple.tuple\tuple.apply\apply_large_arity.pass.cpp
utilities\tuple\tuple.tuple\tuple.cnstr\recursion_depth.pass.cpp

# Deprecation is a mess. We disable all deprecations in msvc_stdlib_force_include.hpp to allow libc++ tests for
# deprecated features to pass, which breaks when libc++ deprecates the feature and adds two tests that (1) pass
# with deprecation suppressed, and (2) fail without deprecation suppression. We should instead translate libc++
# un-deprecation macros to STL un-deprecation macros in the force-include header, and just skip tests when we
# deprecate before they do.
# Deprecation is a mess. We disable all deprecations in llvm-project/libcxx/test/support/msvc_stdlib_force_include.h
# (external to this repo) to allow libc++ tests for deprecated features to pass, which breaks when libc++ deprecates
# the feature and adds two tests that (1) pass with deprecation suppressed, and (2) fail without deprecation suppression.
# We should instead translate libc++ un-deprecation macros to STL un-deprecation macros in the force-include header,
# and just skip tests when we deprecate before they do.
utilities\meta\meta.unary\meta.unary.prop\is_literal_type.deprecated.fail.cpp


Expand Down
3 changes: 2 additions & 1 deletion tests/libcxx/usual_matrix.lst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

RUNALL_INCLUDE ..\universal_prefix.lst
RUNALL_CROSSLIST
PM_CL="/EHsc /MTd /std:c++latest /permissive- /FImsvc_stdlib_force_include.h /wd4643"
# TRANSITION, LLVM-53957: _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS belongs to llvm-project/libcxx/test/support/msvc_stdlib_force_include.h
PM_CL="/EHsc /MTd /std:c++latest /permissive- /FImsvc_stdlib_force_include.h /wd4643 /D_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS"
AlexGuteniev marked this conversation as resolved.
Show resolved Hide resolved
RUNALL_CROSSLIST
PM_CL="/analyze:autolog- /Zc:preprocessor"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing /D_HAS_CXX23"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING

#include <array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define _HAS_DEPRECATED_RAW_STORAGE_ITERATOR 1
#define _SILENCE_CXX17_RAW_STORAGE_ITERATOR_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING
#define _SILENCE_EXPERIMENTAL_ERASE_DEPRECATION_WARNING

#include <algorithm>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING

#include <assert.h>
#include <crtdbg.h>
#include <functional>
Expand Down
1 change: 1 addition & 0 deletions tests/std/tests/P0035R4_over_aligned_allocation/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define _ENABLE_EXTENDED_ALIGNED_STORAGE
#define _HAS_DEPRECATED_TEMPORARY_BUFFER 1
#define _SILENCE_CXX17_TEMPORARY_BUFFER_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING

#include <array>
#include <assert.h>
Expand Down
1 change: 1 addition & 0 deletions tests/std/tests/P0088R3_variant/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define _HAS_DEPRECATED_RESULT_OF 1
#define _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING
#define _SILENCE_CXX20_VOLATILE_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING
#define _LIBCXX_IN_DEVCRT
#include <msvc_stdlib_force_include.h> // Must precede any other libc++ headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _SILENCE_CXX17_POLYMORPHIC_ALLOCATOR_DESTROY_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING

#include <algorithm>
#include <cmath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define _SILENCE_CXX17_IS_LITERAL_TYPE_DEPRECATION_WARNING
#define _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING
#define _SILENCE_CXX20_IS_POD_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING
#define _USE_NAMED_IDL_NAMESPACE 1

#include <array>
Expand Down
3 changes: 3 additions & 0 deletions tests/tr1/tests/type_traits1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// test <type_traits> header, part 1
#define TEST_NAME "<type_traits>, part 1"

#define _SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING

#include "tdefs.h"
#include "typetr.h"
#include <type_traits>
Expand Down
3 changes: 3 additions & 0 deletions tests/tr1/tests/type_traits5/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#define TEST_NAME "<type_traits>, part 5"

#define _DISABLE_EXTENDED_ALIGNED_STORAGE 1
#define _SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING
#define _SILENCE_CXX23_ALIGNED_UNION_DEPRECATION_WARNING

#include "tdefs.h"
#include "typetr.h"
#include <limits.h>
Expand Down