Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<memory>: Guard aligned allocation with __cpp_aligned_new #1689

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -2070,20 +2070,26 @@ template <class _Refc>
_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 <class _Refc>
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<void*>(_Ptr));
} else {
#ifdef __cpp_aligned_new
if constexpr (_Align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
::operator delete (static_cast<void*>(_Ptr), align_val_t{_Align});
} else
#endif // __cpp_aligned_new
{
::operator delete(static_cast<void*>(_Ptr));
}
}

Expand Down