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