GNOME Bugzilla – Bug 760215
G_LIKELY/_UNLIKELY macros need more parentheses
Last modified: 2016-10-11 11:44:23 UTC
Created attachment 318321 [details] [review] fix > $ cat test.c > #include "glib.h" > #define COMMA , > void f(void) { if (G_LIKELY(0 COMMA 1)); } > $ gcc -O -fsyntax-only $(pkg-config --cflags glib-2.0) test.c > test.c: In function ‘f’: > test.c:3:38: error: macro "_G_BOOLEAN_EXPR" passed 2 arguments, but takes just 1
Review of attachment 318321 [details] [review]: Please submit a `git format-patch` patch, see https://wiki.gnome.org/Newcomers/SubmittingPatches
Created attachment 318340 [details] [review] fix ah, conflicting instructions between <https://wiki.gnome.org/Newcomers/SubmittingPatches> and <https://developer.gnome.org/glib/2.47/glib-resources.html#id-1.2.9.4>...
Review of attachment 318340 [details] [review]: It's not worth it for this patch, but in the future I'd like to have descriptions of *real world* use cases too. In this case I'm going to guess it's something OpenOffice is doing - that would be useful to know.
(In reply to Colin Walters from comment #3) > It's not worth it for this patch, but in the future I'd like to have > descriptions of *real world* use cases too. In this case I'm going to guess > it's something OpenOffice is doing - that would be useful to know. No, it's just something I noticed when somebody took that code and copied it to the LibreOffice code base, and I did a code review there, see <http://cgit.freedesktop.org/libreoffice/core/commit/?id=55a5ac48c2abb4c7a97a829d3e9e2db86fafc081> "Get parenthesisation right." I'm not aware of any real-world code affected by this issue.
(In reply to Stephan Bergmann from comment #4) > No, it's just something I noticed when somebody took that code and copied it > to the LibreOffice code base, and I did a code review there, see > <http://cgit.freedesktop.org/libreoffice/core/commit/ > ?id=55a5ac48c2abb4c7a97a829d3e9e2db86fafc081> "Get parenthesisation right." > I'm not aware of any real-world code affected by this issue. Ah hah! That's exactly the kind of useful information I like to see in commit messages.
there is the comment * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when * putting assignments in g_return_if_fail (). https://git.gnome.org/browse/glib/tree/glib/gmacros.h?id=e44ea516afeb41d22cebf968b3ea5d9543856df2#n363 I didn't actually test this, but I think with this change of putting parentheses around (expr), the gcc warning is no longer present. Which makes the comment wrong and the _G_BOOLEAN_EXPR() macro unnecessary.