macros: make G_GNUC_CHECK_VERSION() portable

Desktop / GNOME / GLib - Christian Hergert [redhat.com] - 27 November 2017 10:07 EST

This removes the use of defined() in a macro expansion, which may not be portable to some pre-processors. Instead, we hoist the defined check outside the macro expansion.

https://bugzilla.gnome.org/show_bug.cgi?id=790877

###

diff --git a/glib/gmacros.h b/glib/gmacros.h
index 7b980fb34..4ef143626 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -37,11 +37,14 @@
*/
#include

+#ifdef __GNUC__
#define G_GNUC_CHECK_VERSION(major, minor) \
- (defined(__GNUC__) && \
- ((__GNUC__ > (major)) || \
- ((__GNUC__ == (major)) && \
- (__GNUC_MINOR__ >= (minor)))))
+ ((__GNUC__ > (major)) || \
+ ((__GNUC__ == (major)) && \
+ (__GNUC_MINOR__ >= (minor))))
+#else
+#define G_GNUC_CHECK_VERSION(major, minor) 0
+#endif

/* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
* where this is valid. This allows for warningless compilation of

d44afbadd macros: make G_GNUC_CHECK_VERSION() portable
glib/gmacros.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

Upstream: git.gnome.org


  • Share