utils: fix build error with g++
[project/libubox.git] / utils.h
diff --git a/utils.h b/utils.h
index 6a53b3f..019d817 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -125,11 +125,20 @@ int clock_gettime(int type, struct timespec *tv);
        (sizeof(int) == sizeof(*(1 ? ((void*)((long)(x) * 0l)) : (int*)1)))
 
 #define __eval_once(func, x)                                           \
        (sizeof(int) == sizeof(*(1 ? ((void*)((long)(x) * 0l)) : (int*)1)))
 
 #define __eval_once(func, x)                                           \
-       ({ typeof(x) __x = x; func(__x); })
+       ({ __typeof__(x) __x = x; func(__x); })
 
 
+#ifdef __cplusplus
+/*
+ * g++ does not support __builtin_choose_expr, so always use __eval_once.
+ * Unfortunately this means that the byte order functions can't be used
+ * as a constant expression anymore
+ */
+#define __eval_safe(func, x) __eval_once(func, x)
+#else
 #define __eval_safe(func, x)                                           \
        __builtin_choose_expr(__is_constant(x),                         \
                              func(x), __eval_once(func, x))
 #define __eval_safe(func, x)                                           \
        __builtin_choose_expr(__is_constant(x),                         \
                              func(x), __eval_once(func, x))
+#endif
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN