In Visual Studio, when compiling 64-bit:
sizeof(std::max_align_t)
is 8__STDCPP_DEFAULT_NEW_ALIGNMENT__
is 16
So although std::max_align_t
indicates that implementations of new
should return pointers aligned to a multiple of 8 bytes, allocations with an alignment requirement of 16 bytes don't call the void* operator new (std::size_t count, std::align_val_t);
method but call void* operator new (std::size_t count);
(see https://en.cppreference.com/w/cpp/memory/new/operator_new) and expect them to return a pointer aligned on 16 bytes.
So allocating a struct defined like this:
struct alignas(16) S {double m_value;};
will call the standard operator new
(without std::align_val_t
argument) and expect it to be aligned on 16 bytes, while std::max_align_t
only specifies that it should be aligned on 8 bytes.
This means that when overruling the new
operators, you are forced to align everything on at least 16 bytes, even if 8 bytes would be sufficient.
- Am I missing something?
- Is this an error in the way Visual Studio implements C++/STL?
- Or is this an error in the C++/STL standard?