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

source code of clang-tools-extra/test/clang-tidy/checkers/cert/uppercase-literal-suffix-integer.cpp