Skip to content

Commit

Permalink
P1413R3 Deprecate aligned_storage & aligned_union
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGuteniev committed Feb 19, 2022
1 parent 7b2c54b commit cfc6f17
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private:
friend condition_variable;
friend condition_variable_any;

#pragma warning(suppress : 4996) // warning STL4034: std::aligned_storage is deprecated in C++23 by P1413R3
aligned_storage_t<_Mtx_internal_imp_size, _Mtx_internal_imp_alignment> _Mtx_storage;

_Mtx_t _Mymtx() noexcept { // get pointer to _Mtx_internal_imp_t inside _Mtx_storage
Expand Down Expand Up @@ -698,6 +699,7 @@ public:
}

private:
#pragma warning(suppress : 4996) // warning STL4034: std::aligned_storage is deprecated in C++23 by P1413R3
aligned_storage_t<_Cnd_internal_imp_size, _Cnd_internal_imp_alignment> _Cnd_storage;

_Cnd_t _Mycnd() noexcept { // get pointer to _Cnd_internal_imp_t inside _Cnd_storage
Expand Down
5 changes: 3 additions & 2 deletions stl/inc/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ 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;
Expand All @@ -1046,7 +1046,8 @@ struct _Maximum<_First, _Second, _Rest...> : _Maximum<(_First < _Second ? _Secon
};

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
static constexpr size_t _Max_len = _Maximum<_Len, sizeof(_Types)...>::value; // NOT sizeof...(_Types)
static constexpr size_t alignment_value = _Maximum<alignof(_Types)...>::value;

Expand Down
39 changes: 38 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,43 @@
#define _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
#endif // ^^^ warning disabled ^^^

// next warning number: STL4034
#if _HAS_CXX20 && !defined(_SILENCE_CXX20_IS_ALWAYS_EQUAL_DEPRECATION_WARNING) \
&& !defined(_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS)
#define _CXX20_DEPRECATE_IS_ALWAYS_EQUAL \
[[deprecated("warning STL4033: " \
"std::allocator::is_always_equal is deprecated in C++20 by LWG-3170. " \
"Prefer std::allocator_traits<allocator<T>>::is_always_equal. " \
"You can define _SILENCE_CXX20_IS_ALWAYS_EQUAL_DEPRECATION_WARNING " \
"or _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS to acknowledge that you have received this warning.")]]
#else // ^^^ warning enabled / warning disabled vvv
#define _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
#endif // ^^^ warning disabled ^^^

#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. " \
"Prefer alignas(T) std::byte t_buff[sizeof(T)]." \
"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(T) std::byte t_buff[sizeof(T)]." \
"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
1 change: 1 addition & 0 deletions stl/src/cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "primitives.hpp"

struct _Cnd_internal_imp_t { // condition variable implementation for ConcRT
#pragma warning(suppress : 4996) // warning STL4034: std::aligned_storage is deprecated in C++23 by P1413R3
std::aligned_storage_t<Concurrency::details::stl_condition_variable_max_size,
Concurrency::details::stl_condition_variable_max_alignment>
cv;
Expand Down
1 change: 1 addition & 0 deletions stl/src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern "C" _CRTIMP2 void __cdecl __set_stl_sync_api_mode(__stl_sync_api_modes_en

struct _Mtx_internal_imp_t { // ConcRT mutex
int type;
#pragma warning(suppress : 4996) // warning STL4034: std::aligned_storage is deprecated in C++23 by P1413R3
std::aligned_storage_t<Concurrency::details::stl_critical_section_max_size,
Concurrency::details::stl_critical_section_max_alignment>
cs;
Expand Down
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

0 comments on commit cfc6f17

Please sign in to comment.