mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-02 22:38:01 +00:00
libnm: improve detection for C11 _Generic() support
Older gcc doesn't like this: ../src/libnm-core-impl/nm-setting-wired.c:132:49: error: controlling expression type 'const char *const [31]' not compatible with any generic association type && (nm_utils_strv_find_binary_search(valid_s390_opts, ^~~~~~~~~~~~~~~ ../src/libnm-glib-aux/nm-shared-utils.h:2033:60: note: expanded from macro 'nm_utils_strv_find_binary_search' const char *const *const _strv = NM_CAST_STRV_CC(strv); \ ^ ../src/libnm-glib-aux/nm-macros-internal.h:706:21: note: expanded from macro 'NM_CAST_STRV_CC' (_Generic ((value), \ ^
This commit is contained in:
parent
905f9975d2
commit
54edfc6139
|
@ -1177,7 +1177,7 @@ if test -n "$sanitizers"; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_MSG_CHECKING([CC support C11 _Generic()])
|
AC_MSG_CHECKING([CC support C11 _Generic()])
|
||||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int foo(void); int foo() { int a = 0; int b = _Generic (a, int: 4); return b + a; }]],
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int foo(void); static const char *const buf[1] = { "a" }; int foo() { int a = 0; int b = _Generic (a, int: 4) + _Generic(buf, const char *const*: 5); return b + a; }]],
|
||||||
[[foo();]])],
|
[[foo();]])],
|
||||||
[cc_support_generic=1],
|
[cc_support_generic=1],
|
||||||
[cc_support_generic=0])
|
[cc_support_generic=0])
|
||||||
|
|
14
meson.build
14
meson.build
|
@ -785,11 +785,17 @@ config_h.set('NM_MORE_ASSERTS', more_asserts)
|
||||||
more_logging = get_option('more_logging')
|
more_logging = get_option('more_logging')
|
||||||
config_h.set10('NM_MORE_LOGGING', more_logging)
|
config_h.set10('NM_MORE_LOGGING', more_logging)
|
||||||
|
|
||||||
generic_support_src = 'int main() { int a = 0; int b = _Generic (a, int: 4); return b + a; };'
|
config_h.set10('_NM_CC_SUPPORT_GENERIC',
|
||||||
config_h.set10('_NM_CC_SUPPORT_GENERIC', cc.compiles(generic_support_src))
|
cc.compiles(
|
||||||
|
'int foo(void); static const char *const buf[1] = { "a" }; int foo() { int a = 0; int b = _Generic (a, int: 4) + _Generic(buf, const char *const*: 5); return b + a; }'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
auto_support_src = 'int main() { int a = 0; __auto_type b = a; return b + a; };'
|
config_h.set10('_NM_CC_SUPPORT_AUTO_TYPE',
|
||||||
config_h.set10('_NM_CC_SUPPORT_AUTO_TYPE', cc.compiles(auto_support_src))
|
cc.compiles(
|
||||||
|
'int main() { int a = 0; __auto_type b = a; return b + a; };'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Vala bindings
|
# Vala bindings
|
||||||
vapi_opt = get_option('vapi')
|
vapi_opt = get_option('vapi')
|
||||||
|
|
|
@ -522,9 +522,12 @@ NM_G_ERROR_MSG(GError *error)
|
||||||
/* In the meantime, NetworkManager requires C11 and _Generic() should always be available.
|
/* In the meantime, NetworkManager requires C11 and _Generic() should always be available.
|
||||||
* However, shared/nm-utils may also be used in VPN/applet, which possibly did not yet
|
* However, shared/nm-utils may also be used in VPN/applet, which possibly did not yet
|
||||||
* bump the C standard requirement. Leave this for the moment, but eventually we can
|
* bump the C standard requirement. Leave this for the moment, but eventually we can
|
||||||
* drop it. */
|
* drop it.
|
||||||
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) \
|
*
|
||||||
|| (defined(__clang__))
|
* Technically, gcc 4.9 already has some support for _Generic(). But there seems
|
||||||
|
* to be issues with propagating "const char *[5]" to "const char **". Only assume
|
||||||
|
* we have _Generic() since gcc 5. */
|
||||||
|
#if (defined(__GNUC__) && __GNUC__ >= 5) || (defined(__clang__))
|
||||||
#define _NM_CC_SUPPORT_GENERIC 1
|
#define _NM_CC_SUPPORT_GENERIC 1
|
||||||
#else
|
#else
|
||||||
#define _NM_CC_SUPPORT_GENERIC 0
|
#define _NM_CC_SUPPORT_GENERIC 0
|
||||||
|
|
Loading…
Reference in a new issue