In C++11 the interface of std::vector was changed and functions like resize() are now taking their value_type parameters as reference. This should fix the alignment problem of std::vector entirely and the need for a specialized version unnecessary. So the only thing you have to do in C++11 is use aligned_allocator. But if you include Eigen/StdVector you introduce a partial template specialization of std::vector into your code which replaces the standard implementation as soon as you use aligned_allocator. This silently gives you a C++98 implementation of std::vector and very hard to find errors when using C++11 features (e.g. initializer lists). Code to reproduce the error: #include <vector> #include <Eigen/Eigen> #include <Eigen/StdVector> // <- remove this include to make it work int main() { std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d>> points = { {0,0}, {0,1} }; } So my suggestion to fix this would be to omit specialization of std::vector in case of C++11.
In principle the fix is easy: #if-guard the specialization of the std-containers. But we need a portable way to detect if the implementation is correct already. For gcc checking #if __cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) should be sufficient. What about MSVC and clang?
*** Bug 919 has been marked as a duplicate of this bug. ***
For MSVC, something like #if defined(_MSC_VER) && (_MSC_VER >= 1900) should do the trick. _MSC_VER==1900 for VC++ 2015 Preview; which is the first version where certain things break due to the use of the StdVector header (see Bug 919). The value of __cplusplus still returns 199711L for any current version of Visual Studio, so it cannot be relied on. The above #define from comment #1 should also work for Clang, since Clang returns a proper value for the __cplusplus definition.
Can you check if the following works with VC2015 (with assertions enabled): #include <vector> #include <Eigen/Core> int main() { std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > test; test.resize(2); test.resize(4, Eigen::Matrix4f::Identity()); } If possible, can you also look up the declaration of std::vector::resize in your version? It should get its default value type by const reference (not by value), cf: http://www.cplusplus.com/reference/vector/vector/resize/ There seems to be still the C++98 definition for MSVC2013, according to: http://msdn.microsoft.com/en-us/library/wezs0zy6(v=vs.120).aspx
The above code runs on VS2015 without a problem (tested in release/debug mode on 32 and 64 bit). The std::vector::resize declaration looks like this: void resize(size_type _Newsize, const value_type& _Val)
Thanks for looking into this. I introduced a EIGEN_HAS_CXX11_CONTAINERS macro: https://bitbucket.org/eigen/eigen/commits/2e01c760769be We should also warn from using the EIGEN_DEFINE_STL_{VECTOR,DEQUE,LIST}_SPECIALIZATION macros (which should have said STD instead of STD, btw ...), since these don't propagate the C++11 constructors. Is deprecating a macro possible somehow? I only committed this to the devel branch, since C++11 support of the stable branch is incomplete anyways (and it is easy to workaround this, by not including the corresponding Eigen headers in C++11 mode)
What about defining the EIGEN_DEFINE_STL_* macros to nothing in C++11 mode?
These macros also specialize a container to use the aligned allocator by default: http://eigen.tuxfamily.org/dox-devel/group__TopicStlContainers.html#vector_spec A 'problem' is that most systems are 64bit now and the issue hardly occurs anymore (however, with AVX/32byte alignment it is likely to happen more frequently again). Shall we re-open this as documentation issue?
-- 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/829.