How to suppress the warning "enumeral and non-enumeral type in conditional expression" in GCC

I keep getting this warning from a third-party library (which I don't want to debug), so I really appreciate the way to suppress this particular warning. Google failed me, so I'm here.

+4
source share
4 answers

-Wno-enum-compare bypasses this warning.

see also

+1
source

In gcc4.6 and later, you can use pragma to suppress specific warnings and do this suppression only for a specific block of code, that is:

 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wno-enum-compare" // Code that causes warning goes here #pragma GCC diagnostic pop 

The push / pop function is used to save diagnostic parameters that were set 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 can get stuck with the #pragma GCC system_header !)

Here's a good link to suppress gcc warnings: http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html

This page also describes how to use the -fdiagnostics-show-option to find out which option controls a particular alert.

Of course, in most cases it is preferable to fix the root cause of all warnings than to suppress them! However, sometimes this is not possible.

+1
source

Will the following flag get rid of this warning?

 -Wno-enum-promotion 
0
source

Well, since I could not find a way to disable this particular warning, I resorted to using gcC # pragma system_header. Basically, I wrapped the problem header as follows:

  #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

where foo.h was the problematic header. Now I just turned on this fooWrapper.h and the problem went away. Please note that this should work for some other compilers (MSC and SUNPRO), but I have not tested it.

0
source

Source: https://habr.com/ru/post/1286466/


All Articles