mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
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
This commit is contained in:
parent
d5869fc597
commit
1a6be02260
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user