As described in the doc, structures having Eigen aligned members (e.g. Vector4) may be misaligned when created on the heap with new.
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 ?
In C++11 there is std::allocate_shared that you can use with Eigen's aligned allocator.
(In reply to Gael Guennebaud from comment #1)
> In C++11 there is std::allocate_shared that you can use with Eigen's aligned
std::allocate_shared fails as well in VS2017.
Not sure if it specific to msvc or not.
The code below is enough to reproduce it
auto test = std::allocate_shared<Foo>(Eigen::aligned_allocator<Foo>());
Sorry for get back so late.
Works for me with gcc/clang (while make_shared does fail as expected).
If it don't work with MSVC, then this needs to be reported to VS team.