It's often undesirable but sometimes unavoidable to emit #pragma
directives to suppress and restore warnings. Some compilers support _Pragma
as a way to, among other things, control diagnostics from inside a macro expression.
How to concatenate strings in the arguments of _Pragma discusses how to paste a single string into a _Pragma
statement.
Is there any way to parameterize this? I'd like to combine both _Pragma
directives behind one macro, but that requires pasting tokens together inside of a _Pragma
statement:
#define DO_A_THING(SOME_FLOAT) \
do { \
DISABLE_COMPILER_WARNING(double-promotion) \
call_variadic_function("blah", SOME_FLOAT) \
RESTORE_COMPILER_WARNING() \
} while(0)
DISABLE_COMPILER_WARNING
would expand into something like:
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdouble-promotion\"")
and RESTORE_COMPILER_WARNING
would expand into something like:
_Pragma("GCC diagnostic pop")
Is there a way to author DISABLE_COMPILER_WARNING
to expand out as written?