Eba*_*sin 4 c++ visual-studio c++17
在 MSVC 上编译项目时出现奇怪的错误。
我正在使用 Microsoft Visual Studio 15 2017 并在 c++17(MSVC 版本 15.6.85.37198)中编译
代码在 Clang 和 G++ 上编译,但在 MSVC 上给我一个错误。
我设法将导致错误的代码减少到以下代码段:
#include <cstddef>
struct Point {
double x;
double y;
double z;
};
template<class... Ps>
void doSomething() {
offsetof(Point, x);
}
int main() {
doSomething();
}
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
main.cpp(10): fatal error C1903: unable to recover from previous error(s); stopping compilation [build\example.vcxproj]
Run Code Online (Sandbox Code Playgroud)
起初我有点困惑,因为这是唯一的错误,我花了很长时间才确定问题来自 offsetof。
问题来自offsetof在接受参数包的模板化函数中使用宏。
我认为这段代码没有做任何非法的事情或使用未定义的行为。那么,是我的问题还是编译器中的错误?
谢谢