[英]Reasoning behind “enumeral and non-enumeral type in conditional expression”
[英]How to suppress the “enumeral and non-enumeral type in conditional expression” warning in GCC
我一直从第三方库(我不想调试)得到这个警告,所以我真的很感激能够抑制这个特定的警告。 谷歌让我失望,所以我在这里。
在gcc4.6及更高版本中,您可以使用pragma来抑制特定警告,并仅对特定代码块执行抑制,即:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wno-enum-compare"
// Code that causes warning goes here
#pragma GCC diagnostic pop
推/弹用于保存代码处理之前的诊断选项。
这比使用#pragma GCC system_header
来抑制所有警告要好得多。 (当然,在较旧的gcc中,您可能会被#pragma GCC system_header
方法“卡住”!)
这是一个关于抑制gcc警告的很好的参考: http : //www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
此页面还介绍了如何使用-fdiagnostics-show-option
查找控制特定警告的选项。
当然,确定所有警告的根本原因通常比抑制它们更为可取! 但是,有时这是不可能的。
-Wno-enum-compare
绕过此警告。
以下标志不会摆脱那个警告吗?
-Wno-enum-promotion
好吧,因为我找不到禁用此特定警告的方法,所以我使用了gcc的#pragma system_header。 基本上,我像这样包装有问题的标题:
#if defined __GNUC__ #pragma GCC system_header #elif defined __SUNPRO_CC #pragma disable_warn #elif defined _MSC_VER #pragma warning(push, 1) #endif #include "foo.h" #if defined __SUNPRO_CC #pragma enable_warn #elif defined _MSC_VER #pragma warning(pop) #endif
其中foo.h是有问题的标题。 现在我只是包含这个fooWrapper.h,问题就消失了。 请注意,这也适用于其他一些编译器(MSC和SUNPRO),但我没有测试它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.