std::make_shared fails to fulfill structure aliment
Submitted by Valentin Roussellet
Assigned to Nobody
Link to original bugzilla bug (#1049)
Version: 3.2
Platform: x86 - 32-bit
Description
As described in the doc, structures having Eigen aligned members (e.g. Vector4) may be misaligned when created on the heap with new.
http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
The solution for that issue is to overload the operator new, which is provided as a convenience macro to add in the said struct.
However std::make_shared ignores the overladed operator new as, in at least two implementations of the STD (GNU and MSCV) actually calls the global ::new.
These two codes, while semantically equivalent, behave differently.
std::shared_ptr<Foo> = std:::make_shared<Foo>(...)
std::shared_ptr<Foo> = std:::shared_ptr<Foo>(new Foo(...))
The second one yielding correct alignment while the first one may return a non-aligned pointer.
Would another macro specializing std::make_shared for all types requiring alignment be useful or practical ?
If not, should Eigen provide a make_aligned_shared<T> implementation ?