The non-placement new
expression is specified to invoke an allocation function to allocate storage for an object of the specified type. When successful, the allocation function, in turn, is required to return a pointer to storage with alignment suitable for any object with a fundamental alignment requirement. Although the global operator new
, the default allocation function invoked by the new expression, is specified by the C++ standard [ISO/IEC 14882-2014] to allocate sufficient storage suitably aligned to represent any object of the specified size, since the expected alignment isn't part of the function's interface, the most a program can safely assume is that the storage allocated by the default operator new
defined by the implementation is aligned for an object with a fundamental alignment. In particular, it is unsafe to use the storage for an object of a type with a stricter alignment requirement – an over-aligned type.
...
Avoid relying on the default operator new
to obtain storage for objects of over-aligned types. Doing so may result in an object being constructed at a misaligned location, which has undefined behavior and can result in abnormal termination when the object is accessed even on architectures otherwise known to tolerate misaligned accesses.
...
SEI CERT C++ Coding Standard | MEM54-CPP. Provide placement new with properly aligned pointers to sufficient storage capacity |
Bibliography
[ISO/IEC 14882-2014] | Subclause 3.7.4, "Dynamic Storage Duration" |
[Array New Cookies] | Itanium C++ ABI, version 1.86 |
[N3396] | Dynamic memory allocation for over-aligned data, WG14 proposal |
...