1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// RUN: %check_clang_tidy -std=c++17 %s modernize-use-integer-sign-comparison %t -- \
// RUN: -config="{CheckOptions: {modernize-use-integer-sign-comparison.EnableQtSupport: true}}"
// CHECK-FIXES: #include <QtCore/q20utility.h>
// The code that triggers the check
#define MAX_MACRO(a, b) (a < b) ? b : a
unsigned int FuncParameters(int bla) {
unsigned int result = 0;
if (result == bla)
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_equal(result , bla))
return 1;
}
template <typename T>
void TemplateFuncParameter(T val) {
unsigned long uL = 0;
if (val >= uL)
return;
// CHECK-MESSAGES-NOT: warning:
}
template <typename T1, typename T2>
int TemplateFuncParameters(T1 val1, T2 val2) {
if (val1 >= val2)
return 0;
// CHECK-MESSAGES-NOT: warning:
return 1;
}
int AllComparisons() {
unsigned int uVar = 42;
unsigned short uArray[7] = {0, 1, 2, 3, 9, 7, 9};
int sVar = -42;
short sArray[7] = {-1, -2, -8, -94, -5, -4, -6};
enum INT_TEST {
VAL1 = 0,
VAL2 = -1
};
char ch = 'a';
unsigned char uCh = 'a';
signed char sCh = 'a';
bool bln = false;
if (bln == sVar)
return 0;
// CHECK-MESSAGES-NOT: warning:
if (ch > uCh)
return 0;
// CHECK-MESSAGES-NOT: warning:
if (sVar <= INT_TEST::VAL2)
return 0;
// CHECK-MESSAGES-NOT: warning:
if (uCh < sCh)
return -1;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_less(uCh , sCh))
if ((int)uVar < sVar)
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_less(uVar, sVar))
(uVar != sVar) ? uVar = sVar
: sVar = uVar;
// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: (q20::cmp_not_equal(uVar , sVar)) ? uVar = sVar
while (uArray[0] <= sArray[0])
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: while (q20::cmp_less_equal(uArray[0] , sArray[0]))
if (uArray[1] > sArray[1])
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_greater(uArray[1] , sArray[1]))
MAX_MACRO(uVar, sArray[0]);
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
if (static_cast<unsigned int>(uArray[2]) < static_cast<int>(sArray[2]))
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2])))
// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one.
if ((unsigned int)uArray[3] < (int)sArray[3])
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_less(uArray[3],sArray[3]))
if ((unsigned int)(uArray[4]) < (int)(sArray[4]))
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_less((uArray[4]),(sArray[4])))
if (uArray[5] > sArray[5])
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_greater(uArray[5] , sArray[5]))
#define VALUE sArray[6]
if (uArray[6] > VALUE)
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_greater(uArray[6] , VALUE))
FuncParameters(uVar);
TemplateFuncParameter(sVar);
TemplateFuncParameters(uVar, sVar);
return 0;
}
|