summaryrefslogtreecommitdiffstats
path: root/src/fundamental
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-10-25 19:33:40 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-10-25 20:27:09 +0200
commit0bc4ac526d41483e6e9625d156d753bb3e287a19 (patch)
tree36c1e12597cb35c1fadb10e95a4954a7c4bbbbeb /src/fundamental
parenttree-wide: fix typo (diff)
downloadsystemd-0bc4ac526d41483e6e9625d156d753bb3e287a19.tar.xz
systemd-0bc4ac526d41483e6e9625d156d753bb3e287a19.zip
macro: Use more correct type in IN_SET
This will now catch mistakes like this: struct s { int i:2; } s = { 1 }; assert_se(IN_SET(s.i, ULLONG_MAX)); > warning: implicit conversion from 'unsigned long long' to > 'typeof (+s.i)' (aka 'int') changes value from 18446744073709551615 > to -1 [-Wconstant-conversion]
Diffstat (limited to 'src/fundamental')
-rw-r--r--src/fundamental/macro-fundamental.h8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
index 2536c741c6..58ffaac33c 100644
--- a/src/fundamental/macro-fundamental.h
+++ b/src/fundamental/macro-fundamental.h
@@ -282,11 +282,9 @@
#define IN_SET(x, ...) \
({ \
bool _found = false; \
- /* If the build breaks in the line below, you need to extend the case macros. (We use "long double" as \
- * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \
- * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that \
- * doesn't work, as we want to use this on bitfields and gcc refuses typeof() on bitfields.) */ \
- static const long double __assert_in_set[] _unused_ = { __VA_ARGS__ }; \
+ /* If the build breaks in the line below, you need to extend the case macros. We use typeof(+x) \
+ * here to widen the type of x if it is a bit-field as this would otherwise be illegal. */ \
+ static const typeof(+x) __assert_in_set[] _unused_ = { __VA_ARGS__ }; \
assert_cc(ELEMENTSOF(__assert_in_set) <= 20); \
switch (x) { \
FOR_EACH_MAKE_CASE(__VA_ARGS__) \