如何在clang ++中禁止显示警告? [英] How to suppress a warning in clang++?
问题描述
我编译了以下c ++程序:
I compiled the following c++ program:
int main() { 2==3; }
具有:
clang++-5.0 -std=c++17 -Wunused-comparison prog.cpp
并得到警告:
warning: equality comparison result unused [-Wunused-comparison]
2==3;
~^~~
...因此,这可能不是抑制CLANG中警告的正确方法.
... so, probably this is not the correct way to suppress a warning in CLANG.
在 clang手册,这部分是待办事项".
In the clang manual, this part is a "TODO".
禁用警告的正确命令行标志是什么?
What is the correct command-line flag to disable a warning?
推荐答案
在从中获得的clang诊断程序中:
In the clang diagnostic that you get from:
$ cat main.cpp
int main()
{
2==3;
return 0;
}
$ clang++ -c main.cpp
main.cpp:3:6: warning: equality comparison result unused [-Wunused-comparison]
2==3;
~^~~
1 warning generated.
方括号:
-Wunused-comparison
告诉您 -Wunused-comparison
是负责诊断的已启用警告(在本例中为默认启用).因此,要取消诊断,您可以使用匹配的 -Wno -...
标志显式禁用该警告:
tells you that -Wunused-comparison
is the enabled warning (in this case enabled by default) that was responsible for the diagnostic. So to suppress the diagnostic you explicitly disable that warning with the matching -Wno-...
flag:
$ clang++ -c -Wno-unused-comparison main.cpp; echo Done
Done
GCC也是如此.
通常,禁止警告是鲁re的.宁可慷慨地启用它们- -Wall -Wextra [-pedantic]
-然后修复有问题的代码.
In general, it is reckless to suppress warnings. One should rather enable them generously - -Wall -Wextra [-pedantic]
- and then fix offending code.
这篇关于如何在clang ++中禁止显示警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!