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 <type_traits>
  #include <stdint.h>

  int test() {
      uint16_t a = 0xabcd;
      static_assert(std::is_same_v<decltype(a<<1), uint16_t>);
      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
This commit is contained in:
Piotr Tworek 2021-12-18 22:08:49 +01:00 committed by Christian Helmuth
parent b3f8b49873
commit 27b798fa4f

View File

@ -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