From 27b798fa4f8addaef20ed7bbc0a049406b404e73 Mon Sep 17 00:00:00 2001 From: Piotr Tworek Date: Sat, 18 Dec 2021 22:08:49 +0100 Subject: [PATCH] base: Make int to access_t conversion explicit. As far as I can tell this is not raised by any released GCC versions. Clang 13 on the other hand warns about it due to implicit-int-conversion warning which is automatically enabled together with Wconversion. The problem is relatively simple, shifting access_t value does not always produce result which is also of access_t type. For example, if access_t is uint16_t, shifting it will produce integer result. This can be observed even with GCC. Building the following C++ example will fail: #include #include int test() { uint16_t a = 0xabcd; static_assert(std::is_same_v); return 0; } Changing uint16_t in the static_assert to int, will allow the code to build. Make such int to access_t implicit conversion explicit to allow the code to be compiled with both GCC and clang. Issue #4354 --- repos/base/include/util/register.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repos/base/include/util/register.h b/repos/base/include/util/register.h index 469da04798..b528e2243f 100644 --- a/repos/base/include/util/register.h +++ b/repos/base/include/util/register.h @@ -181,7 +181,7 @@ struct Genode::Register * bitfields into one operation. */ static inline access_t bits(access_t const value) { - return (value & mask()) << SHIFT; } + return access_t((value & mask()) << SHIFT); } /** * Get a register value 'reg' masked according to this bitfield