error C2338: You've instantiated std::aligned_storage《Len, Align》 with an extended alignment.(讨论)


最近在一程序中同时使用到make_shared函数和Eigen库,编译时报如下错误(编译环境VS2017企业版15.9.9):

#include 
#include 
#include 
#include 

struct Object
{
	Eigen::Matrix4d pMatrix;

	Object()
	{
		pMatrix << 0.1, 0, 0, 0,
			0, 0.1, 0, 0,
			0, 0, 0.1, 0,
			0, 0, 0, 0.1;
	}
};

int main(void)
{
	using namespace std;

	shared_ptr shPtr11 = make_shared(); // 使用eigen库时编译报错
	
	shared_ptr shPtr22 = make_shared();
	

	return 0;
}

error C2338: You've instantiated std::aligned_storage 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.(双击可定位到系统头文件


大概意思就是:VS2017 15.8版本修复了老版本有关对齐存储部分缺陷,但修复本身也有缺陷。如果不想编译时报这个问题,就在预编译时定义一个宏 _ENABLE_EXTENDED_ALIGNED_STORAGE 或者 _DISABLE_EXTENDED_ALIGNED_STORAGE(博主的理解是按照修复后的逻辑处理就定义带enable那个,按照老版本的逻辑处理就定义带disable那个)

由于博主建的是一个Empty Project,无预编译头文件,所以进入下图设置后就未再报错:

error C2338: You've instantiated std::aligned_storage《Len, Align》 with an extended alignment.(讨论)_第1张图片


如对存储对齐有深度解读,欢迎评论区留言,谢谢!


 

你可能感兴趣的:(前车之鉴,error,C2338,extended,alignment,Eigen,C++)