1// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -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 -- -target x86_64-pc-linux-gnu -I %clang_tidy_headers
4// RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -target x86_64-pc-linux-gnu -I %clang_tidy_headers
5
6#include "integral_constant.h"
7
8void floating_point_suffix() {
9 static constexpr auto v0 = 1.; // no literal
10 static_assert(is_same<decltype(v0), const double>::value, "");
11 static_assert(v0 == 1., "");
12
13 static constexpr auto v1 = 1.e0; // no literal
14 static_assert(is_same<decltype(v1), const double>::value, "");
15 static_assert(v1 == 1., "");
16
17 // Float
18
19 static constexpr auto v2 = 1.f;
20 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
21 // CHECK-MESSAGES-NEXT: static constexpr auto v2 = 1.f;
22 // CHECK-MESSAGES-NEXT: ^ ~
23 // CHECK-MESSAGES-NEXT: F{{$}}
24 // CHECK-FIXES: static constexpr auto v2 = 1.F;
25 static_assert(is_same<decltype(v2), const float>::value, "");
26 static_assert(v2 == 1.0F, "");
27
28 static constexpr auto v3 = 1.e0f;
29 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
30 // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1.e0f;
31 // CHECK-MESSAGES-NEXT: ^ ~
32 // CHECK-MESSAGES-NEXT: F{{$}}
33 // CHECK-FIXES: static constexpr auto v3 = 1.e0F;
34 static_assert(is_same<decltype(v3), const float>::value, "");
35 static_assert(v3 == 1.0F, "");
36
37 static constexpr auto v4 = 1.F; // OK.
38 static_assert(is_same<decltype(v4), const float>::value, "");
39 static_assert(v4 == 1.0F, "");
40
41 static constexpr auto v5 = 1.e0F; // OK.
42 static_assert(is_same<decltype(v5), const float>::value, "");
43 static_assert(v5 == 1.0F, "");
44
45 // Long double
46
47 static constexpr auto v6 = 1.l;
48 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
49 // CHECK-MESSAGES-NEXT: static constexpr auto v6 = 1.l;
50 // CHECK-MESSAGES-NEXT: ^ ~
51 // CHECK-MESSAGES-NEXT: L{{$}}
52 // CHECK-FIXES: static constexpr auto v6 = 1.L;
53 static_assert(is_same<decltype(v6), const long double>::value, "");
54 static_assert(v6 == 1., "");
55
56 static constexpr auto v7 = 1.e0l;
57 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
58 // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1.e0l;
59 // CHECK-MESSAGES-NEXT: ^ ~
60 // CHECK-MESSAGES-NEXT: L{{$}}
61 // CHECK-FIXES: static constexpr auto v7 = 1.e0L;
62 static_assert(is_same<decltype(v7), const long double>::value, "");
63 static_assert(v7 == 1., "");
64
65 static constexpr auto v8 = 1.L; // OK.
66 static_assert(is_same<decltype(v8), const long double>::value, "");
67 static_assert(v8 == 1., "");
68
69 static constexpr auto v9 = 1.e0L; // OK.
70 static_assert(is_same<decltype(v9), const long double>::value, "");
71 static_assert(v9 == 1., "");
72
73 // __float128
74
75 static constexpr auto v10 = 1.q;
76 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
77 // CHECK-MESSAGES-NEXT: static constexpr auto v10 = 1.q;
78 // CHECK-MESSAGES-NEXT: ^ ~
79 // CHECK-MESSAGES-NEXT: Q{{$}}
80 // CHECK-FIXES: static constexpr auto v10 = 1.Q;
81 static_assert(is_same<decltype(v10), const __float128>::value, "");
82 static_assert(v10 == 1., "");
83
84 static constexpr auto v11 = 1.e0q;
85 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
86 // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 1.e0q;
87 // CHECK-MESSAGES-NEXT: ^ ~
88 // CHECK-MESSAGES-NEXT: Q{{$}}
89 // CHECK-FIXES: static constexpr auto v11 = 1.e0Q;
90 static_assert(is_same<decltype(v11), const __float128>::value, "");
91 static_assert(v11 == 1., "");
92
93 static constexpr auto v12 = 1.Q; // OK.
94 static_assert(is_same<decltype(v12), const __float128>::value, "");
95 static_assert(v12 == 1., "");
96
97 static constexpr auto v13 = 1.e0Q; // OK.
98 static_assert(is_same<decltype(v13), const __float128>::value, "");
99 static_assert(v13 == 1., "");
100}
101
102void floating_point_complex_suffix() {
103 // _Complex, I
104
105 static constexpr auto v14 = 1.i;
106 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
107 // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1.i;
108 // CHECK-MESSAGES-NEXT: ^ ~
109 // CHECK-MESSAGES-NEXT: I{{$}}
110 // CHECK-FIXES: static constexpr auto v14 = 1.I;
111 static_assert(is_same<decltype(v14), const _Complex double>::value, "");
112 static_assert(v14 == 1.I, "");
113
114 static constexpr auto v15 = 1.e0i;
115 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
116 // CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1.e0i;
117 // CHECK-MESSAGES-NEXT: ^ ~
118 // CHECK-MESSAGES-NEXT: I{{$}}
119 // CHECK-FIXES: static constexpr auto v15 = 1.e0I;
120 static_assert(is_same<decltype(v15), const _Complex double>::value, "");
121 static_assert(v15 == 1.I, "");
122
123 static constexpr auto v16 = 1.I; // OK.
124 static_assert(is_same<decltype(v16), const _Complex double>::value, "");
125 static_assert(v16 == 1.I, "");
126
127 static constexpr auto v17 = 1.e0I; // OK.
128 static_assert(is_same<decltype(v17), const _Complex double>::value, "");
129 static_assert(v17 == 1.I, "");
130
131 // _Complex, J
132
133 static constexpr auto v18 = 1.j;
134 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
135 // CHECK-MESSAGES-NEXT: static constexpr auto v18 = 1.j;
136 // CHECK-MESSAGES-NEXT: ^ ~
137 // CHECK-MESSAGES-NEXT: J{{$}}
138 // CHECK-FIXES: static constexpr auto v18 = 1.J;
139 static_assert(is_same<decltype(v18), const _Complex double>::value, "");
140 static_assert(v18 == 1.J, "");
141
142 static constexpr auto v19 = 1.e0j;
143 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
144 // CHECK-MESSAGES-NEXT: static constexpr auto v19 = 1.e0j;
145 // CHECK-MESSAGES-NEXT: ^ ~
146 // CHECK-MESSAGES-NEXT: J{{$}}
147 // CHECK-FIXES: static constexpr auto v19 = 1.e0J;
148 static_assert(is_same<decltype(v19), const _Complex double>::value, "");
149 static_assert(v19 == 1.J, "");
150
151 static constexpr auto v20 = 1.J; // OK.
152 static_assert(is_same<decltype(v20), const _Complex double>::value, "");
153 static_assert(v20 == 1.J, "");
154
155 static constexpr auto v21 = 1.e0J; // OK.
156 static_assert(is_same<decltype(v21), const _Complex double>::value, "");
157 static_assert(v21 == 1.J, "");
158}
159
160void macros() {
161#define PASSTHROUGH(X) X
162 static constexpr auto m0 = PASSTHROUGH(1.f);
163 // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase
164 // CHECK-MESSAGES-NEXT: static constexpr auto m0 = PASSTHROUGH(1.f);
165 // CHECK-MESSAGES-NEXT: ^ ~
166 // CHECK-MESSAGES-NEXT: F{{$}}
167 // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1.F);
168 static_assert(is_same<decltype(m0), const float>::value, "");
169 static_assert(m0 == 1.0F, "");
170}
171

source code of clang-tools-extra/test/clang-tidy/checkers/readability/uppercase-literal-suffix-floating-point.cpp