Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

I'm trying to compile introduce the -Werror flag in an existing codebase. One of the issues I'm encountering is that at some places #warning is used to display informational messages. These should not be treated as an error.

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 anyone help me fix this?

like image 788
StackedCrooked Avatar asked Dec 14 '11 16:12

StackedCrooked


1 Answers

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

In general, pass -fdiagnostics-show-option to have warnings show output like:

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

which tells you a warning flag that controls the warning. In gcc >=4.6 and clang, this is the default, so knowing to pass it may not be too useful anymore.

like image 103
Jeffrey Yasskin Avatar answered Sep 27 '22 21:09

Jeffrey Yasskin