GNOME Bugzilla – Bug 507349
G_STMT_START and G_STMT_END produce ambiguous 'else' in some cases
Last modified: 2009-02-12 02:13:33 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; }
I think this is a duplicate of bug 519026, which has already been fixed.
indeed. *** This bug has been marked as a duplicate of 519026 ***