summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bloomfield <PeterBloomfield@bellsouth.net>2018-05-22 11:26:47 -0400
committerPhilip Withnall <withnall@endlessm.com>2018-05-23 17:49:31 +0100
commit1a6be022600550272638e858a7fbef5e57ce45ba (patch)
tree599684970d999569ca7520c5d70df971eb5e6270
parentd5869fc597f358b2bbb2f1b77afa8636f488a6ee (diff)
downloadglib-1a6be022600550272638e858a7fbef5e57ce45ba.tar.gz
gmem.h: Use typeof() in g_steal_pointer() macro
g_steal_pointer is both an inline function, returning gpointer, and a macro that casts the return value to the type of its argument. The first version of the macro uses '0 ? (*(pp)) : (g_steal_pointer) (pp)' to cast the return value to the type of *pp, but this fails to yield warnings about incompatible pointer types with current gcc. Apparently the ternary operator is optimized away before the type of the expression is determined. The typeof() (or __typeof__()) operator allows an explicit cast. https://bugzilla.gnome.org/show_bug.cgi?id=742456 https://bugzilla.gnome.org/show_bug.cgi?id=796341
-rw-r--r--glib/gmem.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/glib/gmem.h b/glib/gmem.h
index 9530512d0..5cccb045c 100644
--- a/glib/gmem.h
+++ b/glib/gmem.h
@@ -196,8 +196,14 @@ g_steal_pointer (gpointer pp)
}
/* type safety */
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_58
+#define g_steal_pointer(pp) ((__typeof__(*pp)) (g_steal_pointer) (pp))
+#else /* __GNUC__ */
+/* This version does not depend on gcc extensions, but gcc does not warn
+ * about incompatible-pointer-types: */
#define g_steal_pointer(pp) \
(0 ? (*(pp)) : (g_steal_pointer) (pp))
+#endif /* __GNUC__ */
/* Optimise: avoid the call to the (slower) _n function if we can
* determine at compile-time that no overflow happens.