![](/img/trans.png)
[英]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.