How to prevent messages `# warning` from being treated as an error?

I am trying to compile a -Werror flag representation in an existing codebase. One of the problems I am facing is that in some places #warning used to display informational messages. They should not be construed as a mistake.

One solution would be to use #pragma message instead, but this does not seem to be supported by older versions of gcc. (Our build servers use gcc 4.1.2).

Can someone help me fix this?

+8
c ++ gcc
source share
2 answers

In gcc-4.6 and above, you can use -Wno-error=cpp . At least clang released with Lion and later, you can use -Wno-error=#warnings . But since your build servers use the ancient gcc, you are probably out of luck.

In general, pass -fdiagnostics-show-option has warnings showing output, for example:

 test.cc:1:2: warning: #warning hello [-Wcpp] 

which tells you the warning flag that controls the warning. In gcc> = 4.6 and clang, this is the default value, so knowing what to go through may not be very useful.

+4
source share

Locally disable the -Werror effect for #warning as follows:

 #pragma GCC diagnostic push #pragma GCC diagnostic warning "-Wcpp" #warning Informative message: everything is nice and good!!! #pragma GCC diagnostic pop 

The advantage of this approach is that you can still #warning error with #warning in the code.

+1
source share

All Articles