From 87c7018a931581caccc072a993bf9a026bcbe2c1 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 7 Dec 2023 07:52:38 -0800 Subject: [PATCH] Product fix: Truncation warnings in allocate_shared() std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_for_overwrite.pass.cpp memory(2858): warning C4267: 'argument': conversion from 'size_t' to 'test_allocator::size_type', possible loss of data We need to `_Convert_size` when allocating, but if that succeeds, we can simply `static_cast` when deallocating. --- stl/inc/memory | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index b65377e6390..13cd2bd7a72 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -2670,7 +2670,8 @@ private: this->~_Ref_count_unbounded_array_alloc(); - _Al.deallocate(_STD _Refancy<_Alloc_ptr_t<_Rebound_alloc>>(reinterpret_cast<_Storage*>(this)), _Storage_units); + _Al.deallocate(_STD _Refancy<_Alloc_ptr_t<_Rebound_alloc>>(reinterpret_cast<_Storage*>(this)), + static_cast<_Alloc_size_t<_Rebound_alloc>>(_Storage_units)); } }; @@ -2851,11 +2852,12 @@ struct _Allocate_n_ptr { _Alloc_ptr_t<_Alloc> _Ptr; size_t _Nx; - _Allocate_n_ptr(_Alloc& _Al_, const size_t _Nx_) : _Al(_Al_), _Ptr(_Al_.allocate(_Nx_)), _Nx(_Nx_) {} + _Allocate_n_ptr(_Alloc& _Al_, const size_t _Nx_) + : _Al(_Al_), _Ptr(_Al_.allocate(_Convert_size<_Alloc_size_t<_Alloc>>(_Nx_))), _Nx(_Nx_) {} ~_Allocate_n_ptr() { if (_Ptr) { - _Al.deallocate(_Ptr, _Nx); + _Al.deallocate(_Ptr, static_cast<_Alloc_size_t<_Alloc>>(_Nx)); } }