changeset 19707:55397852db0a

lib: Avoid typeof() if HAVE_TYPEOF isn't set, even if gcc version is high enough. This is mainly to test that we can compile without typeof().
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 03 Feb 2016 17:56:49 +0200
parents 3a4866198d8f
children 6d45c0bb9b30
files src/lib/macros.h
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/macros.h	Wed Feb 03 14:05:07 2016 +0200
+++ b/src/lib/macros.h	Wed Feb 03 17:56:49 2016 +0200
@@ -148,7 +148,7 @@
 #endif
 
 /* Macros to provide type safety for callback functions' context parameters */
-#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))
+#if ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)) && defined(HAVE_TYPEOF))
 #  define CALLBACK_TYPECHECK(callback, type) \
 	(COMPILE_ERROR_IF_TRUE(!__builtin_types_compatible_p( \
 		typeof(&callback), type)) ? 1 : 0)
@@ -159,6 +159,11 @@
 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) && !defined(__cplusplus)
 #  define COMPILE_ERROR_IF_TRUE(condition) \
 	(sizeof(char[1 - 2 * !!(condition)]) - 1)
+#else
+#  define COMPILE_ERROR_IF_TRUE(condition) 0
+#endif
+
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) && !defined(__cplusplus) && defined(HAVE_TYPEOF)
 #  define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) \
 	COMPILE_ERROR_IF_TRUE( \
 		!__builtin_types_compatible_p(typeof(_a), typeof(_b)))
@@ -167,7 +172,6 @@
 		!__builtin_types_compatible_p(typeof(_a1), typeof(_b)) && \
 		!__builtin_types_compatible_p(typeof(_a2), typeof(_b)))
 #else
-#  define COMPILE_ERROR_IF_TRUE(condition) 0
 #  define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) 0
 #  define COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE(_a1, _a2, _b) 0
 #endif