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
This commit is contained in:
Thomas Haller 2019-11-09 11:27:14 +01:00
parent b8b8ef7600
commit 45c9f3c39b

View file

@ -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)