What happened with:
#warning "Come back and implement this" #warning "Do not do that!" #warning "Must fix this before release"
Typically, the compiler will include an argument in - or the material after - #warning in the error or warning message.
And, as a rule, if the compiler detects something that requires a warning, it reports this quite clearly.
Given the requirements, I think the only way to handle this is to protect the #warning directives ...
#ifdef DO_WARNINGS #warning "Some warning" #endif /* DO_WARNINGS */
In most cases, you compile without -DDO_WARNINGS ; when you need to check the #warning warnings (with -Werror ), then you turn on -DDO_WARNINGS in the end, acknowledging that the compilation will fail. Remember that make -k will do as much as possible even if there are separate compilation errors.
Section 5.52.9 of GCC 4.4.1 Guidelines (in part):
5.52.9 Diagnostic Pragmas
GCC allows the user to selectively enable or disable certain types of diagnostics and change the type of diagnostics. For example, a project policy might require that all sources be compiled using "-Werror", but certain files may have exceptions that allow certain types of warnings to be used. Or, a project can selectively enable diagnostics and treat them as errors depending on which preprocessor macros are defined.
#pragma GCC diagnostic kind option
Changes the location of the diagnostic. Please note that not all diagnostic changes are subject to change; at the moment, only warnings (usually controlled by "-W ...) may not be all of them. Use the -fdiagnostics-show-option parameter to determine which diagnostics are controlled and which option controls them. kind is a" mistake to cure this Diagnostics as an error, "a warning for its treatment is a warning (even if" -Werror is valid ") or" ignored if the diagnosis is ignored. option is a double-quoted string that matches the command line option.
#pragma GCC diagnostic warning "-Wformat" #pragma GCC diagnostic error "-Wformat" #pragma GCC diagnostic ignored "-Wformat"
Please note that these pragmas override any command line options. Also, although it is syntactically valid to place these pragmas anywhere in your sources, the supported location for them is before any data or functions are defined. otherwise, it can lead to unpredictable results depending on how the optimizer manages your sources. If the same option is specified several times, the last one is the one that is valid. This pragma is not intended to be a general-purpose replacement for command line options, but to implement strict project policy management.
GCC also offers a simple mechanism for printing messages at compile time.
#pragma message string
Prints a string as a compilation message in compilation. A message is informational only and is neither a compilation warning nor an error.
#pragma message "Compiling " __FILE__ "..."
Linecan be bracketed and printed with location information.
I'm not sure if you like editing #warning lines in #pragma message lines. This will help you solve this problem - and it's worse than adding conditional compilation around #warning in that #pragma message can be supported by fewer compilers. It depends on your portability requirements.