<memory>: Guard aligned allocation with __cpp_aligned_new (#1689)

This commit is contained in:
Casey Carter 2021-02-25 18:41:59 -08:00 коммит произвёл GitHub
Родитель 6dd9e24d04
Коммит 9c79c21772
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -2084,20 +2084,26 @@ template <class _Refc>
_NODISCARD _Refc* _Allocate_flexible_array(const size_t _Count) { _NODISCARD _Refc* _Allocate_flexible_array(const size_t _Count) {
const size_t _Bytes = _Calculate_bytes_for_flexible_array<_Refc, _Check_overflow::_Yes>(_Count); const size_t _Bytes = _Calculate_bytes_for_flexible_array<_Refc, _Check_overflow::_Yes>(_Count);
constexpr size_t _Align = alignof(_Refc); constexpr size_t _Align = alignof(_Refc);
if constexpr (_Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { #ifdef __cpp_aligned_new
return static_cast<_Refc*>(::operator new(_Bytes)); if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
} else {
return static_cast<_Refc*>(::operator new (_Bytes, align_val_t{_Align})); return static_cast<_Refc*>(::operator new (_Bytes, align_val_t{_Align}));
} else
#endif // __cpp_aligned_new
{
return static_cast<_Refc*>(::operator new(_Bytes));
} }
} }
template <class _Refc> template <class _Refc>
void _Deallocate_flexible_array(_Refc* const _Ptr) noexcept { void _Deallocate_flexible_array(_Refc* const _Ptr) noexcept {
constexpr size_t _Align = alignof(_Refc); constexpr size_t _Align = alignof(_Refc);
if constexpr (_Align <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) { #ifdef __cpp_aligned_new
::operator delete(static_cast<void*>(_Ptr)); if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
} else {
::operator delete (static_cast<void*>(_Ptr), align_val_t{_Align}); ::operator delete (static_cast<void*>(_Ptr), align_val_t{_Align});
} else
#endif // __cpp_aligned_new
{
::operator delete(static_cast<void*>(_Ptr));
} }
} }