From 45c9f3c39bf3292c000ef0bdbcfa6d84e16b5ca0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 9 Nov 2019 11:27:14 +0100 Subject: [PATCH] shared: make NM_STRUCT_OFFSET_ENSURE_TYPE() work with arrays Some compilers don't convert arrays as _Generic() type selectors to their pointer type. That means, for those compilers the generic type would be an array and not a pointer. Work around that by adding zero to the pointer/array argument. Also, I cannot get this to work with "clang-3.4.2-9.el7". Disable it for that compiler. The value of the generic check is anyway that it only needs to work with some compiler combinations. That will trigger a compilation failure and we can fix the implementation also for compilers that don't support the macro. See-also: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1930.htm --- shared/nm-glib-aux/nm-macros-internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index e2cc7eadab..d1ea04c009 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -635,8 +635,8 @@ NM_G_ERROR_MSG (GError *error) #define _NM_ENSURE_TYPE_CONST(type, value) ((const type) (value)) #endif -#if _NM_CC_SUPPORT_GENERIC -#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) (_Generic ((((container *) NULL)->field), \ +#if _NM_CC_SUPPORT_GENERIC && ( !defined (__clang__) || __clang_major__ > 3 ) +#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) (_Generic ( (&(((container *) NULL)->field))[0] , \ type: G_STRUCT_OFFSET (container, field))) #else #define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) G_STRUCT_OFFSET (container, field)