I'm wondering how to activate GCC compiler flags in code, as opposed to including them in the compilation command on the command line.
Consider the following minimal example, which produces the warning -Wswitch-bool (I think by default but at least with -Wall enabled):
switch (true) {
default:
break;
}
This warning can be suppressed by providing the flag -Wno-switch-bool when compiling the program via the command line.
Is it possible to activate this flag in code? The following naive attempt doesn't work, since Wno-switch-bool is not a legal identifier (dashes are interpreted as minuses):
#define Wno-switch-bool
What is the appropriate command/syntax to use?
Note: This question is not specifically about warnings. I.e. I'm not asking about how to deactivate a specific class of warnings, which I know is best done via #pragma GCC diagnostic ignore, etc. This is a general question about how to enable GCC compiler flags in code. For instance, another example could be how I could activate -Werror, or -fno-implicit-templates via preprocessor directives (whether or not that would be ill-advised).