Add deprecation macro for macros
@ebassi
Submitted by Emmanuele Bassi Link to original bug (#752330)
Description
We have a macro for annotating deprecated functions and generate a compiler warning, but we don't have any way to annotate a deprecated macro. The only way we've found to do that is to use something like:
#ifndef GLIB_DISABLE_DEPRECATED #define THIS_IS_A_DEPRECATED_MACRO #endif
which is a separate symbol, and it triggers a build error instead of a warning; thus nobody actually uses it.
One way to work around this would be to use the GCC and clang-supported _Pragma:
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS #define G_GNUC_DO_PRAGMA(x) _Pragma(#x) #define G_GNUC_DEPRECATED_MACRO(msg) G_GNUC_DO_PRAGMA (GCC warning #msg) #else #define G_GNUC_DEPRECATED_MACRO(msg) #endif
and then re-define the deprecated macros like this:
#define G_UNICODE_COMBINING_MARK
G_GNUC_DEPRECATED_MACRO ("Use G_UNICODE_SPACING_MARK instead")
G_UNICODE_SPACING_MARK
Sadly, GCC does not support a deprecation warning pragma, and the stringification of the arguments makes it hard to do the same kind of stock message string that we use with G_DEPRECATED_FOR.
I've started using this mechanism in Clutter, and it seems to be working fine.
Additionally, it would allow us to add deprecations to enumeration values, like:
#define G_DEPRECATED_ENUM_VALUE(name) name ## _DEPRECATED
enum { FOO, BAR,
G_DEPRECATED_ENUM_VALUE (BAZ),
BLAH };
#define BAZ
G_GNUC_DEPRECATED_MACRO ("Use BLAH instead")
G_DEPRECATED_ENUM_VALUE (BAZ)
Though that may play games with introspection in ways that I have not foreseen.