From 17dc6a9da68a0809cd8d15003d7c940a898a5fb3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 24 May 2019 08:46:48 +0200 Subject: [PATCH] shared: add _NM_ENSURE_TYPE_CONST() The sole purpose of this is more type-safe macros. An alternative solution would be to define a function instead of a macro. But if the function is unused (currently!) you get a compiler warning (on some compilers even when marking the function as "static inline", if it's in the source file). A workaround for that would be to mark the function as _nm_unused, or to use a macro instead. _NM_ENSURE_TYPE_CONST() is to aid the macro solution. --- shared/nm-glib-aux/nm-macros-internal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 77288dde5..1ff90dc5d 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -635,8 +635,10 @@ NM_G_ERROR_MSG (GError *error) * It's useful to check the let the compiler ensure that @value is * of a certain type. */ #define _NM_ENSURE_TYPE(type, value) (_Generic ((value), type: (value))) +#define _NM_ENSURE_TYPE_CONST(type, value) (_Generic ((value), const type: ((const type) (value)), type: ((const type) (value)))) #else #define _NM_ENSURE_TYPE(type, value) (value) +#define _NM_ENSURE_TYPE_CONST(type, value) ((const type) (value)) #endif #if _NM_CC_SUPPORT_GENERIC