From 37f651eaa045e35889efc4b09f75b27ef72379b9 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 26 Mar 2024 01:11:10 +0800 Subject: [PATCH 1/2] Implement P2875R4 Undeprecate `polymorphic_allocator::destroy` --- stl/inc/xpolymorphic_allocator.h | 4 ++-- stl/inc/yvals_core.h | 13 ++----------- .../P0220R1_polymorphic_memory_resources/test.cpp | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/stl/inc/xpolymorphic_allocator.h b/stl/inc/xpolymorphic_allocator.h index d6b34b3d146..660c2694539 100644 --- a/stl/inc/xpolymorphic_allocator.h +++ b/stl/inc/xpolymorphic_allocator.h @@ -296,8 +296,8 @@ namespace pmr { } template - _CXX17_DEPRECATE_POLYMORPHIC_ALLOCATOR_DESTROY void destroy(_Uty* const _Ptr) noexcept /* strengthened */ { - _STD _Destroy_in_place(*_Ptr); + void destroy(_Uty* const _Ptr) noexcept /* strengthened */ { + _Ptr->~_Uty(); } _NODISCARD polymorphic_allocator select_on_container_copy_construction() const noexcept /* strengthened */ { diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index daceb8f32d5..14297c38503 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -132,6 +132,7 @@ // P2338R4 Freestanding Library: Character Primitives And The C Library // (including __cpp_lib_freestanding_charconv) // P2517R1 Conditional noexcept For apply() +// P2875R4 Undeprecate polymorphic_allocator::destroy // _HAS_CXX17 indirectly controls: // N4190 Removing auto_ptr, random_shuffle(), And Old Stuff @@ -1386,17 +1387,7 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect #define _CXX20_DEPRECATE_MOVE_ITERATOR_ARROW #endif // ^^^ warning disabled ^^^ -#if _HAS_CXX17 && !defined(_SILENCE_CXX17_POLYMORPHIC_ALLOCATOR_DESTROY_DEPRECATION_WARNING) \ - && !defined(_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS) -#define _CXX17_DEPRECATE_POLYMORPHIC_ALLOCATOR_DESTROY \ - [[deprecated("warning STL4032: " \ - "std::pmr::polymorphic_allocator::destroy() is deprecated in C++17 by LWG-3036. " \ - "Prefer std::destroy_at() or std::allocator_traits::destroy(). " \ - "You can define _SILENCE_CXX17_POLYMORPHIC_ALLOCATOR_DESTROY_DEPRECATION_WARNING " \ - "or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to suppress this warning.")]] -#else // ^^^ warning enabled / warning disabled vvv -#define _CXX17_DEPRECATE_POLYMORPHIC_ALLOCATOR_DESTROY -#endif // ^^^ warning disabled ^^^ +// STL4032 was "std::pmr::polymorphic_allocator::destroy() is deprecated in C++17 by LWG-3036." (reverted by P2875R4) #if _HAS_CXX20 && !defined(_SILENCE_CXX20_IS_ALWAYS_EQUAL_DEPRECATION_WARNING) \ && !defined(_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS) diff --git a/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp b/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp index 933c0029a63..99f7c1d6ea3 100644 --- a/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp +++ b/tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // 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 From f7848d303428b9da3ed0b57d88b3336e669b4b78 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 26 Mar 2024 00:08:23 -0700 Subject: [PATCH 2/2] Also change `delete_object()`. --- stl/inc/xpolymorphic_allocator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/xpolymorphic_allocator.h b/stl/inc/xpolymorphic_allocator.h index 660c2694539..0903ce5863f 100644 --- a/stl/inc/xpolymorphic_allocator.h +++ b/stl/inc/xpolymorphic_allocator.h @@ -269,7 +269,7 @@ namespace pmr { template void delete_object(_Uty* const _Ptr) noexcept /* strengthened */ { - _STD _Destroy_in_place(*_Ptr); + _Ptr->~_Uty(); deallocate_object(_Ptr); } #endif // _HAS_CXX20