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 ?
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 > allocator. 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 class Foo { Vec4d v; public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; 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.
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1049.