我正在测试Visual Studio代码中的C++17 fallthrough属性。该集成开发环境已配置为使用Microsoft Visual Studio cl.exe编译器编译C/C++代码。我在调试模式下构建一个简单.cpp
文件的任务定义(在tasks.json
中)是:
{
"type": "shell",
"label": "cl.exe: Build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${file}",
"/link",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
]
}
这已经在几个程序上进行了测试,效果很好。现在,我使用新的[[fallthrough]];
属性添加了一条switch
语句,编译器将生成:
warning C5051: attribute 'fallthrough' requires at least '/std:c++17'; ignored
将"/std:c++17",
添加到cl.exe的"args“不会改变任何东西(生成相同的编译器警告)。新版本如下:
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"/std:c++17",
"${file}",
"/link",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
据我所知,根据指定语言标准的Microsoft documentation,我的语法是正确的。
我做错了什么?
发布于 2020-11-24 05:58:58
我在搜索其他东西时发现了这个问题,但这里有一个修复方法:)。
您的问题在于提供参数的顺序。/Fe:
需要紧跟在- https://docs.microsoft.com/en-us/cpp/build/reference/fe-name-exe-file?view=msvc-160之后的文件路径
下面是取自VSCode documentation的示例args
部分,但我添加了/std:c++17
编译器标志
"args": [
"/Zi",
"/EHsc",
"/std:c++17", // <= put your compiler flag here
"/Fe:", // <= /Fe: followed by the path + filename
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
]
希望这对你有所帮助,祝你编码愉快!
https://stackoverflow.com/questions/62915524
复制相似问题