| 1 | // RUN: %check_clang_tidy --match-partial-fixes %s readability-uppercase-literal-suffix %t -- -config="{CheckOptions: {readability-uppercase-literal-suffix.NewSuffixes: 'L;uL'}}" -- -I %clang_tidy_headers |
| 2 | // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp |
| 3 | // RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -config="{CheckOptions: {readability-uppercase-literal-suffix.NewSuffixes: 'L;uL'}}" -- -I %clang_tidy_headers |
| 4 | // RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -config="{CheckOptions: {readability-uppercase-literal-suffix.NewSuffixes: 'L;uL'}}" -- -I %clang_tidy_headers |
| 5 | |
| 6 | #include "integral_constant.h" |
| 7 | |
| 8 | void integer_suffix() { |
| 9 | // Unsigned |
| 10 | |
| 11 | static constexpr auto v3 = 1u; // OK. |
| 12 | static_assert(is_same<decltype(v3), const unsigned int>::value, "" ); |
| 13 | static_assert(v3 == 1, "" ); |
| 14 | |
| 15 | static constexpr auto v4 = 1U; // OK. |
| 16 | static_assert(is_same<decltype(v4), const unsigned int>::value, "" ); |
| 17 | static_assert(v4 == 1, "" ); |
| 18 | |
| 19 | // Long |
| 20 | |
| 21 | static constexpr auto v5 = 1l; |
| 22 | // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'l', which is not uppercase |
| 23 | // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1l; |
| 24 | // CHECK-MESSAGES-NEXT: ^~ |
| 25 | // CHECK-MESSAGES-NEXT: L{{$}} |
| 26 | // CHECK-FIXES: static constexpr auto v5 = 1L; |
| 27 | static_assert(is_same<decltype(v5), const long>::value, "" ); |
| 28 | static_assert(v5 == 1, "" ); |
| 29 | |
| 30 | static constexpr auto v6 = 1L; // OK. |
| 31 | static_assert(is_same<decltype(v6), const long>::value, "" ); |
| 32 | static_assert(v6 == 1, "" ); |
| 33 | |
| 34 | // Long Long |
| 35 | |
| 36 | static constexpr auto v7 = 1ll; // OK. |
| 37 | static_assert(is_same<decltype(v7), const long long>::value, "" ); |
| 38 | static_assert(v7 == 1, "" ); |
| 39 | |
| 40 | static constexpr auto v8 = 1LL; // OK. |
| 41 | static_assert(is_same<decltype(v8), const long long>::value, "" ); |
| 42 | static_assert(v8 == 1, "" ); |
| 43 | |
| 44 | // Unsigned Long |
| 45 | |
| 46 | static constexpr auto v9 = 1ul; |
| 47 | // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'ul', which is not uppercase |
| 48 | // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1ul; |
| 49 | // CHECK-MESSAGES-NEXT: ^~~ |
| 50 | // CHECK-MESSAGES-NEXT: uL{{$}} |
| 51 | // CHECK-FIXES: static constexpr auto v9 = 1uL; |
| 52 | static_assert(is_same<decltype(v9), const unsigned long>::value, "" ); |
| 53 | static_assert(v9 == 1, "" ); |
| 54 | |
| 55 | static constexpr auto v10 = 1uL; // OK. |
| 56 | static_assert(is_same<decltype(v10), const unsigned long>::value, "" ); |
| 57 | static_assert(v10 == 1, "" ); |
| 58 | |
| 59 | static constexpr auto v11 = 1Ul; |
| 60 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Ul', which is not uppercase |
| 61 | // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 1Ul; |
| 62 | // CHECK-MESSAGES-NEXT: ^~~ |
| 63 | // CHECK-MESSAGES-NEXT: uL{{$}} |
| 64 | // CHECK-FIXES: static constexpr auto v11 = 1uL; |
| 65 | static_assert(is_same<decltype(v11), const unsigned long>::value, "" ); |
| 66 | static_assert(v11 == 1, "" ); |
| 67 | |
| 68 | static constexpr auto v12 = 1UL; // OK. |
| 69 | // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'UL', which is not uppercase |
| 70 | // CHECK-MESSAGES-NEXT: static constexpr auto v12 = 1UL; |
| 71 | // CHECK-MESSAGES-NEXT: ^~~ |
| 72 | // CHECK-MESSAGES-NEXT: uL{{$}} |
| 73 | // CHECK-FIXES: static constexpr auto v12 = 1uL; |
| 74 | static_assert(is_same<decltype(v12), const unsigned long>::value, "" ); |
| 75 | static_assert(v12 == 1, "" ); |
| 76 | |
| 77 | // Long Unsigned |
| 78 | |
| 79 | static constexpr auto v13 = 1lu; // OK. |
| 80 | static_assert(is_same<decltype(v13), const unsigned long>::value, "" ); |
| 81 | static_assert(v13 == 1, "" ); |
| 82 | |
| 83 | static constexpr auto v14 = 1Lu; // OK. |
| 84 | static_assert(is_same<decltype(v14), const unsigned long>::value, "" ); |
| 85 | static_assert(v14 == 1, "" ); |
| 86 | |
| 87 | static constexpr auto v15 = 1lU; // OK. |
| 88 | static_assert(is_same<decltype(v15), const unsigned long>::value, "" ); |
| 89 | static_assert(v15 == 1, "" ); |
| 90 | |
| 91 | static constexpr auto v16 = 1LU; // OK. |
| 92 | static_assert(is_same<decltype(v16), const unsigned long>::value, "" ); |
| 93 | static_assert(v16 == 1, "" ); |
| 94 | |
| 95 | // Unsigned Long Long |
| 96 | |
| 97 | static constexpr auto v17 = 1ull; // OK. |
| 98 | static_assert(is_same<decltype(v17), const unsigned long long>::value, "" ); |
| 99 | static_assert(v17 == 1, "" ); |
| 100 | |
| 101 | static constexpr auto v18 = 1uLL; // OK. |
| 102 | static_assert(is_same<decltype(v18), const unsigned long long>::value, "" ); |
| 103 | static_assert(v18 == 1, "" ); |
| 104 | |
| 105 | static constexpr auto v19 = 1Ull; // OK. |
| 106 | static_assert(is_same<decltype(v19), const unsigned long long>::value, "" ); |
| 107 | static_assert(v19 == 1, "" ); |
| 108 | |
| 109 | static constexpr auto v20 = 1ULL; // OK. |
| 110 | static_assert(is_same<decltype(v20), const unsigned long long>::value, "" ); |
| 111 | static_assert(v20 == 1, "" ); |
| 112 | |
| 113 | // Long Long Unsigned |
| 114 | |
| 115 | static constexpr auto v21 = 1llu; // OK. |
| 116 | static_assert(is_same<decltype(v21), const unsigned long long>::value, "" ); |
| 117 | static_assert(v21 == 1, "" ); |
| 118 | |
| 119 | static constexpr auto v22 = 1LLu; // OK. |
| 120 | static_assert(is_same<decltype(v22), const unsigned long long>::value, "" ); |
| 121 | static_assert(v22 == 1, "" ); |
| 122 | |
| 123 | static constexpr auto v23 = 1llU; // OK. |
| 124 | static_assert(is_same<decltype(v23), const unsigned long long>::value, "" ); |
| 125 | static_assert(v23 == 1, "" ); |
| 126 | |
| 127 | static constexpr auto v24 = 1LLU; // OK. |
| 128 | static_assert(is_same<decltype(v24), const unsigned long long>::value, "" ); |
| 129 | static_assert(v24 == 1, "" ); |
| 130 | } |
| 131 | |