const uint32_t gives the error: hicpp bitwise operations on signed integers

2

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?

c++
bitwise-operators
clang-tidy
asked on Stack Overflow Apr 29, 2020 by Amardeep reddy • edited Apr 29, 2020 by Amardeep reddy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0