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 519026 - G_STMT_START/G_STMT_END test a non-existent preprocessor symbol
G_STMT_START/G_STMT_END test a non-existent preprocessor symbol
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal trivial
: ---
Assigned To: gtkdev
gtkdev
: 507349 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-02-27 10:34 UTC by Jean-Yves Lefort
Modified: 2009-02-12 02:13 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jean-Yves Lefort 2008-02-27 10:34:25 UTC
HAVE_DOWHILE_MACROS is never defined since config.h is not included by gmacros.h. It is annoying because the if/else fallback triggers a compiler warning:

===
#include <glib.h>

#define FOO() G_STMT_START{ }G_STMT_END

int main (int argc, char **argv)
{
  if (1)
    FOO();

  return 0;
}
===

$ cc -Wall -std=c99 `pkg-config --cflags --libs glib-2.0` -o test test.c
cc1: warnings being treated as errors
test.c: In function ‘main’:
test.c:7: warning: suggest explicit braces to avoid ambiguous ‘else’
Comment 1 Matthias Clasen 2008-02-27 23:50:16 UTC
That is pretty broken, indeed.

What needs to happen here is:

a) add a G_ prefix to the macro

b) define it in glibconfig.h, not in config.h

c) include glibconfig.h in gmacros.h


Tim ?
Comment 2 Manish Singh 2008-02-28 20:43:57 UTC
It's 2008, is anything that doesn't support do/while(0) even relevant anymore?
Comment 3 Tim Janik 2008-02-29 14:44:32 UTC
(In reply to comment #1)
> That is pretty broken, indeed.
> 
> What needs to happen here is:
> 
> a) add a G_ prefix to the macro
> 
> b) define it in glibconfig.h, not in config.h
> 
> c) include glibconfig.h in gmacros.h
> 
> 
> Tim ?

i completely agree with yosh, there should be nothing out there that has problems with do{}while(0), which is why i used that already for some assertion macros. i think we can simply switch G_STMT* to always say do{}while(0) at this point.
any takers up for this? tbf?
Comment 4 Jean-Yves Lefort 2008-05-22 01:50:44 UTC
This too will rot forever, right?
Comment 5 Tim Janik 2008-05-22 08:53:53 UTC
2008-05-22 10:49:37  Tim Janik  <timj@imendio.com>

        * glib/gmacros.h: implement G_STMT_START and G_STMT_END with
        do{}while(0), which is believed to be widely portable, fixes:
     Bug 519026 - G_STMT_START/G_STMT_END test a non-existent preprocessor symbol
Comment 6 Matthias Clasen 2009-02-12 02:13:33 UTC
*** Bug 507349 has been marked as a duplicate of this bug. ***