如何抑制“条件表达式中的枚举和非枚举类型” 海湾合作委员会警告
我不断从第三方库(我不想调试)收到此警告,因此我非常感谢有一种方法来抑制此特定警告。 谷歌让我失望了,所以我来了。
I keep getting this warning from a third-party library (which I don't want to debug), so I'd really appreciate a way to suppress this specific warning. Google failed me, so here I am.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-Wno-enum-compare
绕过此警告。另请参阅
-Wno-enum-compare
bypasses this warning.See also
在 gcc4.6 及更高版本中,您可以使用 pragma 来抑制特定警告,并仅对特定代码块进行抑制,即:
push/pop 用于保留在处理代码之前就位的诊断选项。
这将是比使用#pragma GCC system_header 抑制所有警告更好的方法。 (当然,在较旧的 gcc 中,您可能会被
#pragma GCC system_header
方法“卡住”!)这里有一个关于抑制 gcc 警告的很好的参考:http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
此页面还介绍了如何使用
-fdiagnostics -show-option
找出哪个选项控制特定警告。当然,通常来说,解决所有警告的根本原因比抑制它们要好得多! 然而,有时这是不可能的。
In gcc4.6 and later you can use pragma's to suppress specific warnings and do that suppression only to a specific block of code, i.e. :
The push/pop are used to preserve the diagnostic options that were in place before your code was processed.
This would be a much better approach than using
#pragma GCC system_header
to suppress all warnings. (Of course, in older gcc you may be "stuck" with the#pragma GCC system_header
approach!)Here's a nice reference on suppressing gcc warnings: http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
This page also describes how to use
-fdiagnostics-show-option
to find out what option controls a particular warning.Of course, it's generally far preferable to fix the root cause of all warnings than to suppress them! However, sometimes that is not possible.
好吧,由于我找不到禁用此特定警告的方法,因此我求助于使用 gcc 的#pragma system_header。 基本上,我像这样包装了有问题的标头:
其中 foo.h 是有问题的标头。 现在我只要包含这个 fooWrapper.h 问题就消失了。 请注意,这也应该适用于其他一些编译器(MSC 和 SUNPRO),但我没有测试它。
Well, since I couldn't find a way to disable this specific warning, I resorted to using gcc's #pragma system_header. Basically, I wrapped the problematic header like this:
where foo.h was the problematic header. Now I just include this fooWrapper.h and the problem goes away. Note that this should work for some other compilers too (MSC and SUNPRO), but I didn't test it.
下面的标志不会消除该警告吗?
Won't the following flag get rid of that warning?