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 = 0x0p0; // no literal
10 static_assert(is_same<decltype(v0), const double>::value, "");
11 static_assert(v0 == 0, "");
12
13 // Float
14
15 static constexpr auto v1 = 0xfp0f;
16 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
17 // CHECK-MESSAGES-NEXT: static constexpr auto v1 = 0xfp0f;
18 // CHECK-MESSAGES-NEXT: ^ ~
19 // CHECK-MESSAGES-NEXT: F{{$}}
20 // CHECK-FIXES: static constexpr auto v1 = 0xfp0F;
21 static_assert(is_same<decltype(v1), const float>::value, "");
22 static_assert(v1 == 15, "");
23
24 static constexpr auto v2 = 0xfp0F; // OK
25 static_assert(is_same<decltype(v2), const float>::value, "");
26 static_assert(v2 == 15, "");
27
28 static constexpr auto v3 = 0xfP0f;
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 = 0xfP0f;
31 // CHECK-MESSAGES-NEXT: ^ ~
32 // CHECK-MESSAGES-NEXT: F{{$}}
33 // CHECK-FIXES: static constexpr auto v3 = 0xfP0F;
34 static_assert(is_same<decltype(v3), const float>::value, "");
35 static_assert(v3 == 15, "");
36
37 static constexpr auto v4 = 0xfP0F; // OK
38 static_assert(is_same<decltype(v4), const float>::value, "");
39 static_assert(v4 == 15, "");
40
41 static constexpr auto v5 = 0xFP0f;
42 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
43 // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 0xFP0f;
44 // CHECK-MESSAGES-NEXT: ^ ~
45 // CHECK-MESSAGES-NEXT: F{{$}}
46 // CHECK-FIXES: static constexpr auto v5 = 0xFP0F;
47 static_assert(is_same<decltype(v5), const float>::value, "");
48 static_assert(v5 == 15, "");
49
50 static constexpr auto v6 = 0xFP0F; // OK
51 static_assert(is_same<decltype(v6), const float>::value, "");
52 static_assert(v6 == 15, "");
53
54 static constexpr auto v7 = 0xFp0f;
55 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
56 // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 0xFp0f;
57 // CHECK-MESSAGES-NEXT: ^ ~
58 // CHECK-MESSAGES-NEXT: F{{$}}
59 // CHECK-FIXES: static constexpr auto v7 = 0xFp0F;
60 static_assert(is_same<decltype(v7), const float>::value, "");
61 static_assert(v7 == 15, "");
62
63 static constexpr auto v8 = 0xFp0F; // OK
64 static_assert(is_same<decltype(v8), const float>::value, "");
65 static_assert(v8 == 15, "");
66
67 // long double
68
69 static constexpr auto v9 = 0xfp0l;
70 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
71 // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 0xfp0l;
72 // CHECK-MESSAGES-NEXT: ^ ~
73 // CHECK-MESSAGES-NEXT: L{{$}}
74 // CHECK-FIXES: static constexpr auto v9 = 0xfp0L;
75 static_assert(is_same<decltype(v9), const long double>::value, "");
76 static_assert(v9 == 0xfp0, "");
77
78 static constexpr auto v10 = 0xfp0L; // OK.
79 static_assert(is_same<decltype(v10), const long double>::value, "");
80 static_assert(v10 == 0xfp0, "");
81
82 // __float128
83
84 static constexpr auto v11 = 0xfp0q;
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 = 0xfp0q;
87 // CHECK-MESSAGES-NEXT: ^ ~
88 // CHECK-MESSAGES-NEXT: Q{{$}}
89 // CHECK-FIXES: static constexpr auto v11 = 0xfp0Q;
90 static_assert(is_same<decltype(v11), const __float128>::value, "");
91 static_assert(v11 == 0xfp0, "");
92
93 static constexpr auto v12 = 0xfp0Q; // OK.
94 static_assert(is_same<decltype(v12), const __float128>::value, "");
95 static_assert(v12 == 0xfp0, "");
96}
97
98void floating_point_complex_suffix() {
99 // _Complex, I
100
101 static constexpr auto v14 = 0xfp0i;
102 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
103 // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 0xfp0i;
104 // CHECK-MESSAGES-NEXT: ^ ~
105 // CHECK-MESSAGES-NEXT: I{{$}}
106 // CHECK-FIXES: static constexpr auto v14 = 0xfp0I;
107 static_assert(is_same<decltype(v14), const _Complex double>::value, "");
108 static_assert(v14 == 0xfp0I, "");
109
110 static constexpr auto v16 = 0xfp0I; // OK.
111 static_assert(is_same<decltype(v16), const _Complex double>::value, "");
112 static_assert(v16 == 0xfp0I, "");
113
114 // _Complex, J
115
116 static constexpr auto v18 = 0xfp0j;
117 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
118 // CHECK-MESSAGES-NEXT: static constexpr auto v18 = 0xfp0j;
119 // CHECK-MESSAGES-NEXT: ^ ~
120 // CHECK-MESSAGES-NEXT: J{{$}}
121 // CHECK-FIXES: static constexpr auto v18 = 0xfp0J;
122 static_assert(is_same<decltype(v18), const _Complex double>::value, "");
123 static_assert(v18 == 0xfp0J, "");
124
125 static constexpr auto v20 = 0xfp0J; // OK.
126 static_assert(is_same<decltype(v20), const _Complex double>::value, "");
127 static_assert(v20 == 0xfp0J, "");
128}
129
130void macros() {
131#define PASSTHROUGH(X) X
132 static constexpr auto m0 = PASSTHROUGH(0x0p0f);
133 // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase
134 // CHECK-MESSAGES-NEXT: static constexpr auto m0 = PASSTHROUGH(0x0p0f);
135 // CHECK-MESSAGES-NEXT: ^ ~
136 // CHECK-MESSAGES-NEXT: F{{$}}
137 // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(0x0p0F);
138 static_assert(is_same<decltype(m0), const float>::value, "");
139 static_assert(m0 == 0x0p0F, "");
140}
141

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