changeset 21910:0bcfd58922bd

lib: Add a common HAVE_TYPE_CHECKS I'm not sure if it should be checking gcc >= 3.0 or 3.3, but they're all old so doesn't really matter. The __cplusplus check was added to both, since it wouldn't have done anything anyway as COMPILE_ERROR_IF_TRUE() is 0 for __cplusplus.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 07 Apr 2017 09:11:53 +0300
parents 57ce096eab4b
children abfa9d470305
files src/lib/compat.h src/lib/macros.h
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/compat.h	Wed Apr 05 15:59:51 2017 +0300
+++ b/src/lib/compat.h	Fri Apr 07 09:11:53 2017 +0300
@@ -11,6 +11,11 @@
 #  define LLONG_MAX 9223372036854775807LL
 #endif
 
+#if ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)) && \
+	defined(HAVE_TYPEOF)) && !defined(__cplusplus)
+#  define HAVE_TYPE_CHECKS
+#endif
+
 /* We really want NULL to be a pointer, since we have various type-checks
    that may result in compiler warnings/errors if it's not. */
 #ifndef __cplusplus
--- a/src/lib/macros.h	Wed Apr 05 15:59:51 2017 +0300
+++ b/src/lib/macros.h	Fri Apr 07 09:11:53 2017 +0300
@@ -148,7 +148,7 @@
 #endif
 
 /* Macros to provide type safety for callback functions' context parameters */
-#if ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)) && defined(HAVE_TYPEOF))
+#ifdef HAVE_TYPE_CHECKS
 #  define CALLBACK_TYPECHECK(callback, type) \
 	(COMPILE_ERROR_IF_TRUE(!__builtin_types_compatible_p( \
 		typeof(&callback), type)) ? 1 : 0)
@@ -163,7 +163,7 @@
 #  define COMPILE_ERROR_IF_TRUE(condition) 0
 #endif
 
-#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) && !defined(__cplusplus) && defined(HAVE_TYPEOF)
+#ifdef HAVE_TYPE_CHECKS
 #  define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) \
 	COMPILE_ERROR_IF_TRUE( \
 		!__builtin_types_compatible_p(typeof(_a), typeof(_b)))