I'd like to add some macros to ease (un)setting a specific warning around routines that we are deprecating internally.
I'd like to turn this:
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wdeprecated-declarations"
void Foo() __attribute__((deprecated("Warning: deprecated routine")))
#pragma clang diagnostic pop
into this:
MY_DEPRECATED_BEGIN
void Foo() MY_DEPRECATED
MY_DEPRECATED_END
The MY_DEPRECATED_BEGIN
macro is giving me trouble as I have to specify two pragmas in a single macro. Can this be done?
(Bonus points for a solution that achieves the same effect using only the MY_DEPRECATED macro!)
You can use this solution:
Then just add it:
The short answer to your technical question is that C99 provides the
_Pragma("foo")
construct, which is equivalent to#pragma foo
but is processed slightly later, and doesn't need to be on a line by itself.Your other problem is that
-Wdeprecated-declarations
doesn't do what you think it does. Simply declaring a function as deprecated will never give you a diagnostic, because__attribute__((deprecated))
is supposed to be used (generally in header files). What causes the diagnostic is if you use a deprecated function — and it's at that point that the setting of-Wdeprecated
becomes relevant.If you really just want to deprecate
Foo
iffMY_DEPRECATED
is set, then the right way to do that is