-Werror causes compiler to stop on #warning. What can I do to prevent this?
c, c-preprocessor, embedded, gcc, preprocessor-directive
Solution
I am not familiar with the Tensilica Xtensa compiler (`xt-xcc`), but with standard GCC you can use
#pragma GCC diagnostic warning "-Wcpp"
to make `#warning` a matter of simple warning (not an error because of `-Werror`). To make the effect temporary, you can embrace this `#pragma` and the `#warning` between `#pragma GCC diagnostic push` and `#pragma GCC diagnostic pop`.
When I compile a file containing the following
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wcpp"
#warning one
#pragma GCC diagnostic pop
#warning two
with `-Werror` using GCC 4.6.1 (command `gcc -c -Werror warning-test.c`), I get the following output:
lang-none warning-test.c:3:2: warning: #warning one [-Wcpp] warning-test.c:6:2: error: #warning two [-Werror=cpp] cc1: all warnings being treated as errors
`
When I remove the second `#warning`, the compilation is not interrupted by an error.
You can also replace your `-Werror` compiler options with `-Werror -Wno-error=cpp`. I am not aware what other effects the `cpp` category of warnings include (and you might have a legitimate `#warning` in some other place that you want to catch as error), so temporarily disabling the error for a specific `#warning` and restoring the settings immediately after seems more accurate method of meeting your requirements.
Using GCC versions 4.8.4 and 4.9.2 gives pretty much the same behavior (only the source line is printed out additionally). But using GCC version 5.0.1 (prerelease version included in Ubuntu 15.04 (Vivid Vervet)) will give two warnings unless option `-Werror=cpp` is included as well. So it seems that `-Werror` with a newer GCC does not anymore imply `-Werror=cpp` like before and it needs to be provided separately if desired.
Problem
First off, I want it to stop on warnings. But I also want to print out some informative messages (like "Come back and implement this!"). Unfortunately, my compiler doesn't support `#info`, `#message`, `#pragma message()`, etc. I know there's `-Wno-error=<something>`, but my google-foo is weak, and I can't seem to find out the `<something>` for `#warning`. I've tried `-Wno-error=warning`, and that just says "there's no `-Wwarning`". Same with "`warn`". Any suggestions? For what its worth, I'm using the Tensilica Xtensa compiler, xt-xcc, which appears to be a GNU derivative, or at least uses the GNU front end. It's version 8.0.0.