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 772743 - macros: generate uniq variable name in _G_BOOLEAN_EXPR()/G_LIKELY()
macros: generate uniq variable name in _G_BOOLEAN_EXPR()/G_LIKELY()
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-10-11 11:07 UTC by Thomas Haller
Modified: 2018-05-24 19:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
macros: generate uniq variable name in _G_BOOLEAN_EXPR()/G_LIKELY() (2.01 KB, patch)
2016-10-11 11:07 UTC, Thomas Haller
reviewed Details | Review

Description Thomas Haller 2016-10-11 11:07:41 UTC
This avoids a -Wshadow warning when nesting G_LIKELY() inside
each other due to _g_boolean_var_.

This can be easily encountered when using macros:

    #define GET_VALUE(arg) \
        ({ \
           typeof (arg) _arg = (arg); \
           \
           g_assert (_arg); \
           get_value (_arg); \
        })
    g_assert (GET_VALUE (a) > 5);

__COUNTER__ is a GCC extension, but the definition of _G_BOOLEAN_EXPR()
is already inside a
  #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
block.
Comment 1 Thomas Haller 2016-10-11 11:07:46 UTC
Created attachment 337400 [details] [review]
macros: generate uniq variable name in _G_BOOLEAN_EXPR()/G_LIKELY()
Comment 2 Thomas Haller 2016-10-11 11:46:13 UTC
or maybe just drop _G_BOOLEAN_EXPR entirely. See: https://bugzilla.gnome.org/show_bug.cgi?id=760215#c6
Comment 3 Colin Walters 2016-11-22 18:32:48 UTC
Review of attachment 337400 [details] [review]:

::: glib/gmacros.h
@@ +370,2 @@
    if (expr)                                    \
+      G_PASTE (_g_boolean_var_, uniq) = 1;      \

Couldn't we just use:

expr ? 1 : 0

?
Comment 4 Thomas Haller 2016-11-22 18:52:18 UTC
I guess, originally it was implemented that way because

 * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
 * putting assignments in g_return_if_fail ().

But I don't think that works anymore. See https://bugzilla.gnome.org/show_bug.cgi?id=760215#c6 . Which makes _G_BOOLEAN_EXPR() in this form pointless.
Comment 5 GNOME Infrastructure Team 2018-05-24 19:09:26 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1211.