241 lines · cpp
1// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -I %clang_tidy_headers2 3#include "integral_constant.h"4#include <cstddef>5 6void integer_suffix() {7 static constexpr auto v0 = __LINE__; // synthetic8 static constexpr auto v1 = __cplusplus; // synthetic, long9 10 static constexpr auto v2 = 1; // no literal11 static_assert(is_same<decltype(v2), const int>::value, "");12 static_assert(v2 == 1, "");13 14 // Unsigned15 16 static constexpr auto v3 = 1u;17 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'u', which is not uppercase18 // CHECK-FIXES: static constexpr auto v3 = 1U;19 static_assert(is_same<decltype(v3), const unsigned int>::value, "");20 static_assert(v3 == 1, "");21 22 static constexpr auto v4 = 1U; // OK.23 static_assert(is_same<decltype(v4), const unsigned int>::value, "");24 static_assert(v4 == 1, "");25 26 // Long27 28 static constexpr auto v5 = 1l;29 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'l', which is not uppercase30 // CHECK-FIXES: static constexpr auto v5 = 1L;31 static_assert(is_same<decltype(v5), const long>::value, "");32 static_assert(v5 == 1, "");33 34 static constexpr auto v6 = 1L; // OK.35 static_assert(is_same<decltype(v6), const long>::value, "");36 static_assert(v6 == 1, "");37 38 // Long Long39 40 static constexpr auto v7 = 1ll;41 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'll', which is not uppercase42 // CHECK-FIXES: static constexpr auto v7 = 1LL;43 static_assert(is_same<decltype(v7), const long long>::value, "");44 static_assert(v7 == 1, "");45 46 static constexpr auto v8 = 1LL; // OK.47 static_assert(is_same<decltype(v8), const long long>::value, "");48 static_assert(v8 == 1, "");49 50 // Unsigned Long51 52 static constexpr auto v9 = 1ul;53 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'ul', which is not uppercase54 // CHECK-FIXES: static constexpr auto v9 = 1UL;55 static_assert(is_same<decltype(v9), const unsigned long>::value, "");56 static_assert(v9 == 1, "");57 58 static constexpr auto v10 = 1uL;59 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'uL', which is not uppercase60 // CHECK-FIXES: static constexpr auto v10 = 1UL;61 static_assert(is_same<decltype(v10), const unsigned long>::value, "");62 static_assert(v10 == 1, "");63 64 static constexpr auto v11 = 1Ul;65 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Ul', which is not uppercase66 // CHECK-FIXES: static constexpr auto v11 = 1UL;67 static_assert(is_same<decltype(v11), const unsigned long>::value, "");68 static_assert(v11 == 1, "");69 70 static constexpr auto v12 = 1UL; // OK.71 static_assert(is_same<decltype(v12), const unsigned long>::value, "");72 static_assert(v12 == 1, "");73 74 // Long Unsigned75 76 static constexpr auto v13 = 1lu;77 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'lu', which is not uppercase78 // CHECK-FIXES: static constexpr auto v13 = 1LU;79 static_assert(is_same<decltype(v13), const unsigned long>::value, "");80 static_assert(v13 == 1, "");81 82 static constexpr auto v14 = 1Lu;83 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Lu', which is not uppercase84 // CHECK-FIXES: static constexpr auto v14 = 1LU;85 static_assert(is_same<decltype(v14), const unsigned long>::value, "");86 static_assert(v14 == 1, "");87 88 static constexpr auto v15 = 1lU;89 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'lU', which is not uppercase90 // CHECK-FIXES: static constexpr auto v15 = 1LU;91 static_assert(is_same<decltype(v15), const unsigned long>::value, "");92 static_assert(v15 == 1, "");93 94 static constexpr auto v16 = 1LU; // OK.95 static_assert(is_same<decltype(v16), const unsigned long>::value, "");96 static_assert(v16 == 1, "");97 98 // Unsigned Long Long99 100 static constexpr auto v17 = 1ull;101 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'ull', which is not uppercase102 // CHECK-FIXES: static constexpr auto v17 = 1ULL;103 static_assert(is_same<decltype(v17), const unsigned long long>::value, "");104 static_assert(v17 == 1, "");105 106 static constexpr auto v18 = 1uLL;107 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'uLL', which is not uppercase108 // CHECK-FIXES: static constexpr auto v18 = 1ULL;109 static_assert(is_same<decltype(v18), const unsigned long long>::value, "");110 static_assert(v18 == 1, "");111 112 static constexpr auto v19 = 1Ull;113 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Ull', which is not uppercase114 // CHECK-FIXES: static constexpr auto v19 = 1ULL;115 static_assert(is_same<decltype(v19), const unsigned long long>::value, "");116 static_assert(v19 == 1, "");117 118 static constexpr auto v20 = 1ULL; // OK.119 static_assert(is_same<decltype(v20), const unsigned long long>::value, "");120 static_assert(v20 == 1, "");121 122 // Long Long Unsigned123 124 static constexpr auto v21 = 1llu;125 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'llu', which is not uppercase126 // CHECK-FIXES: static constexpr auto v21 = 1LLU;127 static_assert(is_same<decltype(v21), const unsigned long long>::value, "");128 static_assert(v21 == 1, "");129 130 static constexpr auto v22 = 1LLu;131 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'LLu', which is not uppercase132 // CHECK-FIXES: static constexpr auto v22 = 1LLU;133 static_assert(is_same<decltype(v22), const unsigned long long>::value, "");134 static_assert(v22 == 1, "");135 136 static constexpr auto v23 = 1llU;137 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'llU', which is not uppercase138 // CHECK-FIXES: static constexpr auto v23 = 1LLU;139 static_assert(is_same<decltype(v23), const unsigned long long>::value, "");140 static_assert(v23 == 1, "");141 142 static constexpr auto v24 = 1LLU; // OK.143 static_assert(is_same<decltype(v24), const unsigned long long>::value, "");144 static_assert(v24 == 1, "");145}146 147void integer_complex_suffix() {148 // _Complex, I149 150 static constexpr auto v25 = 1i;151 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'i', which is not uppercase152 // CHECK-FIXES: static constexpr auto v25 = 1I;153 static_assert(is_same<decltype(v25), const _Complex int>::value, "");154 static_assert(v25 == 1I, "");155 156 static constexpr auto v26 = 1I; // OK.157 static_assert(is_same<decltype(v26), const _Complex int>::value, "");158 static_assert(v26 == 1I, "");159 160 // _Complex, J161 162 static constexpr auto v27 = 1j;163 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'j', which is not uppercase164 // CHECK-FIXES: static constexpr auto v27 = 1J;165 static_assert(is_same<decltype(v27), const _Complex int>::value, "");166 static_assert(v27 == 1J, "");167 168 static constexpr auto v28 = 1J; // OK.169 static_assert(is_same<decltype(v28), const _Complex int>::value, "");170 static_assert(v28 == 1J, "");171}172 173void macros() {174#define PASSTHROUGH(X) X175 static constexpr auto m0 = PASSTHROUGH(1u);176 // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: integer literal has suffix 'u', which is not uppercase177 // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1U);178 static_assert(is_same<decltype(m0), const unsigned int>::value, "");179 static_assert(m0 == 1, "");180 181 // This location is inside a macro, no warning on that by default.182#define MACRO 1u183 int foo = MACRO;184}185 186// Check that user-defined literals do not cause any diags.187 188unsigned long long int operator"" _ull(unsigned long long int);189void user_defined_literals() {190 1_ull;191}192 193template <unsigned alignment>194void template_test() {195 static_assert(alignment, "");196}197void actual_template_test() {198 template_test<4>();199}200 201const int table[6] = {};202void read_test() {203 for (auto i : table) {204 }205}206 207namespace {208enum a { b };209constexpr bool operator&(a, a) { return int(); }210template <a l>211void c() { l &a(); }212void d();213void d() { c<b>(); }214} // namespace215 216// Check that non-type template parameters do not cause any diags.217// https://bugs.llvm.org/show_bug.cgi?id=51790218template <int capacity>219struct Vector {220 static constexpr int kCapacity = capacity;221};222 223template <int capacity>224constexpr int Vector<capacity>::kCapacity;225// CHECK-MESSAGES-NOT: :[[@LINE-1]]:22: warning: integer literal has suffix 'ity', which is not uppercase226 227template <int foo1u>228struct Foo {229 static constexpr int kFoo = foo1u;230};231 232template <int foo1u>233constexpr int Foo<foo1u>::kFoo;234// CHECK-MESSAGES-NOT: :[[@LINE-1]]:19: warning: integer literal has suffix 'u', which is not uppercase235 236// The template needs to be instantiated for diagnostics to show up237void test_non_type_template_parameter() {238 int x = Vector<10>::kCapacity;239 int f = Foo<10>::kFoo;240}241