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 507349 - G_STMT_START and G_STMT_END produce ambiguous 'else' in some cases
G_STMT_START and G_STMT_END produce ambiguous 'else' in some cases
Status: RESOLVED DUPLICATE of bug 519026
Product: glib
Classification: Platform
Component: general
2.15.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-01-04 20:45 UTC by Sebastian Dröge (slomo)
Modified: 2009-02-12 02:13 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Sebastian Dröge (slomo) 2008-01-04 20:45:02 UTC
Hi,
starting with gcc 4.3 G_STMT_START and G_STMT_END produce a "ambiguous 'else'" compiler warning in some cases but only when compiling in C++ mode (i.e. using g++ instead of gcc for example). One small example code is at the bottom.

The warning is caused by the following expansion:

if (123)
  if (1) {
    printf ("123");
  } else
    (void) 0;

and of course the warning is correct there. Forcing it to use the __extension__ variant of G_STMT_START/STOP in gmacros.h removes this warning, defining HAVE_DOWHILE_MACROS has the same effect. Is it a bug in my code that HAVE_DOWHILE_MACROS is not defined normally? Shouldn't this be documented somewhere that this is necessary for those macros then?


#include <stdio.h>
#include <glib.h>

#define foo(x) \
  G_STMT_START { \
    printf (x); \
  } G_STMT_END

int main()
{
  if (123)
    foo ("123");
  return 0;
}
Comment 1 Matt Kraai 2009-02-03 00:18:15 UTC
I think this is a duplicate of bug 519026, which has already been fixed.
Comment 2 Matthias Clasen 2009-02-12 02:13:33 UTC
indeed.


*** This bug has been marked as a duplicate of 519026 ***