[[deprecated]]
void foo(){};
int main()
{
foo();
}
上面的代码在 VS2017 中产生以下错误:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>deprecation.cpp
1>d:\source\deprecation.cpp(6): error C4996: 'foo': was declared deprecated
1>d:\source\deprecation.cpp(2): note: see declaration of 'foo'
1>Done building project "test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
不幸的是,搜索此错误会导致大量“如何使用 [[deprecated]]”和“哪些函数已被弃用?” 风格问题。
我检查的每个资源似乎都建议使用 [[deprecated]] 应该像上面写的一样简单 - 编译器错误/警告是预期的,但不是构建失败。注释掉 [[deprecated]] 行会导致构建成功。
项目的目标是 Windows SDK 版本 10.0.17763.0。
cl.exe 版本为 19.16.27027。
我在使用 [[deprecated]] 时是否遗漏了一些明显的东西,或者 VS2017 是否找到了打破它的方法?