【发布时间】:2019-01-03 20:06:04
【问题描述】:
我已在 VS2017(15.9 版)和 VS2019 预览版上尝试过以下代码 - 这是误报吗?
class Base {};
class Derived1 : public virtual Base {}; // to avoid diamond pattern in real code
class Derived2 : public Base {};
struct S1 {
int i;
void(Derived1::*func)(); // warning C4121 - see below for full text
};
struct S2 {
int i;
void(Derived2::*func)(); // no warning
};
int main()
{
}
r:\cpp2019\cpp2019\cpp2019.cpp(9) : warning C4121 : 'S1' : alignment of a member was sensitive to packing
我已经使代码尽可能简单(显然它不是实际的生产代码)。在生产代码(一个巨大的代码库)中,警告是由于使用基于范围的 for 循环对地图进行迭代。 循环变量当然是std::pair<keytype, valuetype>,值类型类似于struct S1中的func。
生产代码在 VS2015 中编译良好,但现在使用 VS2017 并且语言标准设置为 C++17,我收到此警告。
【问题讨论】:
-
@JesperJuhl - 如果您阅读我的解释,这是不可能的。实际代码中的结构是
std::pair。 -
您是使用
#pragma pack还是将/Zp标志传递给编译器?
标签: c++ visual-c++ visual-studio-2017 c++17