This forum has been archived. All content is frozen. Please use KDE Discuss instead.

VS2017 15.8 std::aligned_storage error

Tags: None
(comma "," separated)
abray
Registered Member
Posts
1
Karma
0
Hi all,

Having updated the compiler in Visual Studio 2017 to use the latest version ( 15.8 ), I ran into an interesting issue compiling code using Eigen and how it may affect other projects.

This is the error

Code: Select all
Error   C2338   You've instantiated std::aligned_storage<Len, Align> with an extended alignment (in other words, Align > alignof(max_align_t)).
Before VS 2017 15.8, the member type would non-conformingly have an alignment of only alignof(max_align_t).
VS 2017 15.8 was fixed to handle this correctly, but the fix inherently changes layout and breaks binary compatibility (*only* for uses of aligned_storage with extended alignments).
Please define either (1) _ENABLE_EXTENDED_ALIGNED_STORAGE to acknowledge that you understand this message and that you actually want a type with an extended alignment,
or (2) _DISABLE_EXTENDED_ALIGNED_STORAGE to silence this message and get the old non-conformant behavior.   
CommonDataModel   c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.15.26726\include\type_traits   1271   


It has to do with us allocating a class that contains an Eigen object with fixed-size dimensions with make_shared

You can demonstrate the problem by compiling the following code.
The error will be produced, but only by the line using the make_shared allocation, the other allocations do not produce the error.

Code: Select all
#include <Eigen/Core>
struct Foo
{
  Eigen::Matrix<double, 2, 1> vector2d;
};
std::shared_ptr<Foo> make1() { return std::shared_ptr<Foo>(new Foo); }// No Error
std::shared_ptr<Foo> make2() { return std::make_shared<Foo>(); }// Produces the Error
Foo* make3() { return new Foo; }// No Error


Eigen performs optimal vectorization on these fixed-sized objects and that seems to include some alignment specification
You can turn off the vectorization of Eigen objects (and alignment) to not get this error
But I think the best solution is to accept Microsoft's update to 15.8 by adding a processor definition to your application and keep Eigen vectorization.

I don't feel that this is an Eigen issue to solve (set this flag for anyone using Eigen and MSVC)
But you may want to add a warning or note in your documentation about this.

For CMake users you will need to add a preprocessor definition with something like:

Code: Select all
if(MSVC AND ${MSVC_VERSION} GREATER_EQUAL 1915)
  # You must acknowledge that you understand MSVC resolved a byte alignment issue in this compiler
  # We get this due to using Eigen objects and allocating those objects with make_shared
  target_compile_definitions( ${target_name} PRIVATE _ENABLE_EXTENDED_ALIGNED_STORAGE )
endif()


Hope this might save some time for others who may run into this problem with the latest update from MSVC


Thanks
twithaar
Registered Member
Posts
23
Karma
0
There's a way to annotate your structure that should resolve the warnings:
https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell