From 9cc1ee931b08bd2401c4011459584b05e2a490e5 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Tue, 23 Feb 2021 08:17:12 -0800 Subject: [PATCH] ``: Guard aligned allocation with __cpp_aligned_new We introduced a couple of unguarded uses in `` in #309 "P0674R1 `make_shared` For Arrays". Fixes DevCom-1346191. Fixes AB-1283107. --- stl/inc/memory | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index ae479ece7b..2a3c0cf3ce 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -2070,20 +2070,26 @@ template _NODISCARD _Refc* _Allocate_flexible_array(const size_t _Count) { const size_t _Bytes = _Calculate_bytes_for_flexible_array<_Refc, _Check_overflow::_Yes>(_Count); constexpr size_t _Align = alignof(_Refc); - if constexpr (_Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - return static_cast<_Refc*>(::operator new(_Bytes)); - } else { +#ifdef __cpp_aligned_new + if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { return static_cast<_Refc*>(::operator new (_Bytes, align_val_t{_Align})); + } else +#endif // __cpp_aligned_new + { + return static_cast<_Refc*>(::operator new(_Bytes)); } } template void _Deallocate_flexible_array(_Refc* const _Ptr) noexcept { constexpr size_t _Align = alignof(_Refc); - if constexpr (_Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - ::operator delete(static_cast(_Ptr)); - } else { +#ifdef __cpp_aligned_new + if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { ::operator delete (static_cast(_Ptr), align_val_t{_Align}); + } else +#endif // __cpp_aligned_new + { + ::operator delete(static_cast(_Ptr)); } }