Skip to content

Commit

Permalink
<xmemory>: Remove std::allocator<void> full specialization (micro…
Browse files Browse the repository at this point in the history
…soft#2726)

Co-authored-by: Casey Carter <[email protected]>
Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
3 people authored and fsb4000 committed Aug 13, 2022
1 parent 2c64b50 commit 08705f3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
17 changes: 10 additions & 7 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ public:
}

_NODISCARD _CONSTEXPR20 __declspec(allocator) _Ty* allocate(_CRT_GUARDOVERFLOW const size_t _Count) {
static_assert(sizeof(value_type) > 0, "value_type must be complete before calling allocate.");
return static_cast<_Ty*>(_Allocate<_New_alignof<_Ty>>(_Get_size_of_n<sizeof(_Ty)>(_Count)));
}

Expand Down Expand Up @@ -866,28 +867,30 @@ public:
static constexpr size_t _Minimum_allocation_alignment = _Asan_granularity;
};

#if _HAS_DEPRECATED_ALLOCATOR_VOID || _HAS_DEPRECATED_ALLOCATOR_MEMBERS
template <>
class allocator<void> {
public:
using value_type = void;
#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS typedef void* pointer;
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS typedef const void* const_pointer;

template <class _Other>
struct _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS rebind {
using other = allocator<_Other>;
};
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS

#if _HAS_CXX20
using size_type = size_t;
using difference_type = ptrdiff_t;

using propagate_on_container_move_assignment = true_type;
using is_always_equal _CXX20_DEPRECATE_IS_ALWAYS_EQUAL = true_type;

#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
template <class _Other>
struct _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS rebind {
using other = allocator<_Other>;
};
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS
#endif // _HAS_CXX20
};
#endif // _HAS_DEPRECATED_ALLOCATOR_VOID || _HAS_DEPRECATED_ALLOCATOR_MEMBERS

template <class _Ty, class _Other>
_NODISCARD _CONSTEXPR20 bool operator==(const allocator<_Ty>&, const allocator<_Other>&) noexcept {
Expand Down
4 changes: 4 additions & 0 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,10 @@
#define _HAS_DEPRECATED_ALLOCATOR_MEMBERS (_HAS_FEATURES_REMOVED_IN_CXX20)
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS

#ifndef _HAS_DEPRECATED_ALLOCATOR_VOID
#define _HAS_DEPRECATED_ALLOCATOR_VOID (_HAS_FEATURES_REMOVED_IN_CXX20)
#endif // _HAS_DEPRECATED_ALLOCATOR_VOID

#ifndef _HAS_DEPRECATED_IS_LITERAL_TYPE
#define _HAS_DEPRECATED_IS_LITERAL_TYPE (_HAS_FEATURES_REMOVED_IN_CXX20)
#endif // _HAS_DEPRECATED_IS_LITERAL_TYPE
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ tests\GH_000431_lex_compare_family
tests\GH_000431_lex_compare_memcmp_classify
tests\GH_000442_random_subtract_with_carry_engine_io
tests\GH_000457_system_error_message
tests\GH_000527_remove_allocator_void
tests\GH_000545_include_compare
tests\GH_000625_vector_bool_optimization
tests\GH_000685_condition_variable_any
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_000527_remove_allocator_void/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _SILENCE_CXX20_IS_ALWAYS_EQUAL_DEPRECATION_WARNING

#include <memory>
#include <type_traits>
#include <utility>

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

using namespace std;

template <class T, class = void>
constexpr bool has_member_size_type = false;

template <class T>
constexpr bool has_member_size_type<T, void_t<typename T::size_type>> = true;

template <class T, class = void>
constexpr bool has_member_difference_type = false;

template <class T>
constexpr bool has_member_difference_type<T, void_t<typename T::difference_type>> = true;

template <class T, class = void>
constexpr bool has_member_pocma = false;

template <class T>
constexpr bool has_member_pocma<T, void_t<typename T::propagate_on_container_move_assignment>> = true;

template <class T, class = void>
constexpr bool has_member_is_always_equal = false;

template <class T>
constexpr bool has_member_is_always_equal<T, void_t<typename T::is_always_equal>> = true;

template <class T, class = void>
constexpr bool can_allocate = false;

template <class T>
constexpr bool can_allocate<T, void_t<decltype(declval<T&>().allocate(size_t{}))>> = true;

STATIC_ASSERT(has_member_size_type<allocator<int>>);
STATIC_ASSERT(has_member_difference_type<allocator<int>>);
STATIC_ASSERT(has_member_pocma<allocator<int>>);
STATIC_ASSERT(has_member_is_always_equal<allocator<int>>);
STATIC_ASSERT(can_allocate<allocator<int>>);
STATIC_ASSERT(is_convertible_v<allocator<void>, allocator<int>>);

#if _HAS_CXX20
constexpr bool has_cxx20 = true;
#else
constexpr bool has_cxx20 = false;
#endif

STATIC_ASSERT(has_cxx20 == has_member_size_type<allocator<void>>);
STATIC_ASSERT(has_cxx20 == has_member_difference_type<allocator<void>>);
STATIC_ASSERT(has_cxx20 == has_member_pocma<allocator<void>>);
STATIC_ASSERT(has_cxx20 == has_member_is_always_equal<allocator<void>>);
STATIC_ASSERT(has_cxx20 == can_allocate<allocator<void>>);
STATIC_ASSERT(has_cxx20 == is_convertible_v<allocator<int>, allocator<void>>);

int main() {} // COMPILE-ONLY

0 comments on commit 08705f3

Please sign in to comment.