使用 /analyze 时,如何禁用包含引号(而不是尖括号)的标头中的 MSVC 警告?
我正在尝试将 /analyze
标志添加到 cl
中。
即使我使用 /analyze:external-
和 /external:I ,我还是收到来自外部标头 I
。#include "..."
的警告。 ..
我做错了什么?
示例项目:
main.cpp
#include "external.h"
// #include <external.h> <- hides external's warnings
int main() {
int shadowed = 0;
{ float shadowed = 0; }
return 0;
}
external.h
void something() {
int external_shadowed = 0;
{ float external_shadowed = 0; }
}
我从 VS 运行此命令开发者提示:
cl /EHsc /analyze /analyze:external- /I include /external:I external /external:W0 main.cpp
我继续从这两个文件中获取警告。
I am trying to add the /analyze
flag to cl
.
I am getting a warnings from external headers I #include "..."
, even though I am using /analyze:external-
and /external:I ...
.
What am I doing wrong?
Example project:
main.cpp
#include "external.h"
// #include <external.h> <- hides external's warnings
int main() {
int shadowed = 0;
{ float shadowed = 0; }
return 0;
}
external.h
void something() {
int external_shadowed = 0;
{ float external_shadowed = 0; }
}
I run this command from the VS developer prompt:
cl /EHsc /analyze /analyze:external- /I include /external:I external /external:W0 main.cpp
And I proceed to get warnings from both files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/analyze:external-
和/external:I
无效可能还有一个原因:您在项目加载后立即检查 CA 结果。可能是一个错误,但可以从 MSVC 菜单或构建时手动启动 CA
配置 ->代码分析->一般->在构建时启用代码分析
对我来说与开始输出不同,实际上使用排除规则。
There may be an additional reason why
/analyze:external-
and/external:I
have no effect: you check CA result right after project load.Possibly a bug, but starting CA manually from MSVC menu or on build
Configuration -> Code Analysis -> General -> Enable Code Analysis on Build
for me is different from starting output and actually uses exclude rules.
看来 MSVC 只认为
/external:I
目录实际上是外部的,如果它们包含在<>
而不是""
中。这没有在任何地方记录,我认为这是编译器的错误。第三方库不一定总是包含在<>
中。更多信息以及将来可能的更新:https ://developercommunity.visualstudio.com/t/analyze:external--and-external:I-flags/1688240
我没有测试了我自己,但是 根据 Hwi -sung Im [MSFT]、
<>
和""
现在的行为相同Visual Studio 2022 17.0 中的 wrt/external:I
。It seems MSVC only considers
/external:I
directories to actually be external if they are included with<>
instead of""
. This is not documented anywhere, and I would consider it a bug with the compiler. Third-party libraries should not necessarily always be included with<>
.More info and possibly updates in the future here: https://developercommunity.visualstudio.com/t/analyze:external--and-external:I-flags/1688240
I have not tested myself, but according to Hwi-sung Im [MSFT],
<>
and""
now act the same w.r.t/external:I
in Visual Studio 2022 17.0.