After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 614965 - Add new G_GNUC_DEPRECATED_FOR macro
Add new G_GNUC_DEPRECATED_FOR macro
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-04-06 14:42 UTC by Emmanuele Bassi (:ebassi)
Modified: 2011-02-18 16:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add G_GNUC_DEPRECATED_FOR macro (1.61 KB, patch)
2010-04-06 15:22 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review

Description Emmanuele Bassi (:ebassi) 2010-04-06 14:42:16 UTC
apparently, gcc 4.5 will add an optional argument for the deprecated __attribute__. this should allow better error message reporting when compiling a project using deprecated functions/types.

we should probably add a new G_GNUC_DEPRECATED_FOR macro defined as:

  G_GNUC_DEPRECATED_FOR(t)

which would expand to:

  __attribute__ ((deprecated ("Use ##t instead")))

this way we could have:

  void
  my_foo_bar (MyFoo *foo,
              gint   bar) G_GNUC_DEPRECATED_FOR (gtk_foo_set_bar);

giving out an error message like:

  warning: ‘gtk_foo_bar’ is deprecated: Use gtk_foo_set_bar instead

the fallback for previous versions of gcc is

  #define G_GNUC_DEPRECATED_FOR(s) G_GNUC_DEPRECATED

the patch is trivial, and I'll be able to do it as soon as I have a gcc 4.5 version to play with.
Comment 1 Emmanuele Bassi (:ebassi) 2010-04-06 14:53:32 UTC
just for reference, the upstream bug is:

  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43666
Comment 2 Emmanuele Bassi (:ebassi) 2010-04-06 15:22:00 UTC
Created attachment 158052 [details] [review]
Add G_GNUC_DEPRECATED_FOR macro

It would be good, error reporting-wise, to be able to signal which
function should be used instead of a deprecated one. GCC 4.5 added an
optional "message" payload to the deprecated attribute, so that:

  void f1 (void) __attribute__((deprecated("Use f2 instead")));

Will expand to:

  warning: f1 is deprecated: Use f2 instead

Instead of just printing:

  warning: f1 is deprecated

Since we already have a G_GNUC_DEPRECATED macro we should provide a
G_GNUC_DEPRECATED_FOR macro defined as:

  G_GNUC_DEPRECATED_FOR(bar)

Which would expand the deprecation message to "Use bar instead"
automatically. The deprecation message should probably be similar
to what we use in gtk-doc to match up with the documentation.
Comment 3 Matthias Clasen 2010-04-22 23:54:50 UTC
Comment on attachment 158052 [details] [review]
Add G_GNUC_DEPRECATED_FOR macro

nice
Comment 4 Emmanuele Bassi (:ebassi) 2010-04-23 14:35:09 UTC
Attachment 158052 [details] pushed as 38e2273 - Add G_GNUC_DEPRECATED_FOR macro