1 | // RUN: %check_clang_tidy %s hicpp-signed-bitwise %t -- \ |
2 | // RUN: -config="{CheckOptions: {hicpp-signed-bitwise.IgnorePositiveIntegerLiterals: true}}" \ |
3 | // RUN: -- -std=c++11 |
4 | |
5 | void examples() { |
6 | unsigned UValue = 40u; |
7 | unsigned URes; |
8 | |
9 | URes = UValue & 1u; //Ok |
10 | URes = UValue & -1; |
11 | // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use of a signed integer operand with a binary bitwise operator |
12 | |
13 | unsigned URes2 = URes << 1; //Ok |
14 | unsigned URes3 = URes & 1; //Ok |
15 | |
16 | int IResult; |
17 | IResult = 10 & 2; //Ok |
18 | IResult = 3 << -1; |
19 | // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use of a signed integer operand with a binary bitwise operator |
20 | |
21 | int Int = 30; |
22 | IResult = Int << 1; |
23 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
24 | IResult = ~0; //Ok |
25 | IResult = -1 & 1; |
26 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator [hicpp-signed-bitwise] |
27 | } |
28 | |
29 | enum EnumConstruction { |
30 | one = 1, |
31 | two = 2, |
32 | test1 = 1 << 12, //Ok |
33 | test2 = one << two, |
34 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use of a signed integer operand with a binary bitwise operator |
35 | test3 = 1u << 12, //Ok |
36 | }; |
37 | |