From f307e120806fb28e20aedba7ceafd13081e07241 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 15 Mar 2022 23:46:33 +0100 Subject: [PATCH] std-aux: cast NM_IN_SET_SET() operands to "int" for "-Wbitwise-instead-of-logical" warning Clang 14 has a new warning "-Wbitwise-instead-of-logical", and it warns about our usage with NM_IN_SET_SE()/NM_IN_STRSET_SE(). It complains that we are using '|' with boolean operands. Which is true (and intended), as we bitwise-or the result of the '==' comparisons. Work around the warning by casting the operands to "int". Note that in C, the comparison operators have already a type "int", so this cast should not result in any changes in the compiled code. ../src/libnm-core-impl/tests/test-general.c:9415:17: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical] _ASSERT(2, !NM_IN_SET_SE(-1, G(1), G(2))); ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/libnm-std-aux/nm-std-aux.h:800:30: note: expanded from macro 'NM_IN_SET_SE' #define NM_IN_SET_SE(x, ...) _NM_IN_SET(|, typeof(x), x, __VA_ARGS__) ^ ../src/libnm-std-aux/nm-std-aux.h:789:39: note: expanded from macro '_NM_IN_SET' !!(NM_VA_ARGS_FOREACH(, , op, _NM_IN_SET_OP, __VA_ARGS__)); \ ^ ../src/libnm-std-aux/nm-std-aux.h:772:20: note: expanded from macro 'NM_VA_ARGS_FOREACH' op, \ ^ note: (skipping 7 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) ../src/libnm-glib-aux/nm-macros-internal.h:1603:47: note: expanded from macro '_G_BOOLEAN_EXPR' #define _G_BOOLEAN_EXPR(expr) NM_BOOLEAN_EXPR(expr) ~~~~~~~~~~~~~~~~^~~~~ ../src/libnm-std-aux/nm-std-aux.h:167:62: note: expanded from macro 'NM_BOOLEAN_EXPR' #define NM_BOOLEAN_EXPR(expr) _NM_BOOLEAN_EXPR_IMPL(NM_UNIQ, expr) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ ../src/libnm-std-aux/nm-std-aux.h:161:13: note: expanded from macro '_NM_BOOLEAN_EXPR_IMPL' if (expr) \ ^~~~ ../src/libnm-core-impl/tests/test-general.c:9415:17: note: cast one or both operands to int to silence this warning ../src/libnm-std-aux/nm-std-aux.h:800:30: note: expanded from macro 'NM_IN_SET_SE' #define NM_IN_SET_SE(x, ...) _NM_IN_SET(|, typeof(x), x, __VA_ARGS__) ^ ../src/libnm-std-aux/nm-std-aux.h:789:39: note: expanded from macro '_NM_IN_SET' !!(NM_VA_ARGS_FOREACH(, , op, _NM_IN_SET_OP, __VA_ARGS__)); \ ^ --- src/libnm-std-aux/nm-std-aux.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 9e5ffa0364..c44bcc7283 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -778,7 +778,7 @@ nm_streq0(const char *s1, const char *s2) /*****************************************************************************/ -#define _NM_IN_SET_OP(x, idx) (_x == (x)) +#define _NM_IN_SET_OP(x, idx) ((int) (_x == (x))) #define _NM_IN_SET(op, type, x, ...) \ ({ \ type _x = (x); \ @@ -814,7 +814,7 @@ _NM_IN_STRSET_EVAL_op_streq(const char *x1, const char *x) return x && nm_streq(x1, x); } -#define _NM_IN_STRSET_EVAL_OP_NULL(x, idx) (((const char *) NULL) == (x)) +#define _NM_IN_STRSET_EVAL_OP_NULL(x, idx) ((int) (((const char *) NULL) == (x))) #define _NM_IN_STRSET_EVAL_OP_STREQ(x, idx) _NM_IN_STRSET_EVAL_op_streq(_x1, x) #define _NM_IN_STRSET_EVAL(op, eval_op, x1, ...) \ ({ \