The code below gives me a clang-tidy error:
[clang-tidy] hicpp bitwise operations on signed integers
// File 1: Clang - Tidy not enabled
typedef struct A {
struct { uint32_t b; } c;
} A;
// File 2: Clang-Tidy enabled
A *ptr;
// Some code that assigns values at the address pointed by ptr
...
...
const uint32_t mask = 0xFFFF0000;
uint32_t masked_var = ptr->c.b & mask;
When I change the code as shown below, that error is gone:
uint32_t masked_var = ptr->c.b & (static_cast<uint32_t>(mask));
In this example, isn't mask
already unsigned?
User contributions licensed under CC BY-SA 3.0