19081d3d8SHaojian Wu // RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %clang_tidy_headers
289a1d03eSRichard // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
39081d3d8SHaojian Wu // RUN: clang-tidy %t.cpp -checks='-*,readability-uppercase-literal-suffix' -fix -- -target x86_64-pc-linux-gnu -I %clang_tidy_headers
49081d3d8SHaojian Wu // 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
589a1d03eSRichard 
69081d3d8SHaojian Wu #include "integral_constant.h"
789a1d03eSRichard 
floating_point_suffix()889a1d03eSRichard void floating_point_suffix() {
989a1d03eSRichard   static constexpr auto v0 = 1.; // no literal
1089a1d03eSRichard   static_assert(is_same<decltype(v0), const double>::value, "");
1189a1d03eSRichard   static_assert(v0 == 1., "");
1289a1d03eSRichard 
1389a1d03eSRichard   static constexpr auto v1 = 1.e0; // no literal
1489a1d03eSRichard   static_assert(is_same<decltype(v1), const double>::value, "");
1589a1d03eSRichard   static_assert(v1 == 1., "");
1689a1d03eSRichard 
1789a1d03eSRichard   // Float
1889a1d03eSRichard 
1989a1d03eSRichard   static constexpr auto v2 = 1.f;
2089a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
2189a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v2 = 1.f;
2289a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
23*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: F{{$}}
2489a1d03eSRichard   // CHECK-FIXES: static constexpr auto v2 = 1.F;
2589a1d03eSRichard   static_assert(is_same<decltype(v2), const float>::value, "");
2689a1d03eSRichard   static_assert(v2 == 1.0F, "");
2789a1d03eSRichard 
2889a1d03eSRichard   static constexpr auto v3 = 1.e0f;
2989a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase
3089a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1.e0f;
3189a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
32*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: F{{$}}
3389a1d03eSRichard   // CHECK-FIXES: static constexpr auto v3 = 1.e0F;
3489a1d03eSRichard   static_assert(is_same<decltype(v3), const float>::value, "");
3589a1d03eSRichard   static_assert(v3 == 1.0F, "");
3689a1d03eSRichard 
3789a1d03eSRichard   static constexpr auto v4 = 1.F; // OK.
3889a1d03eSRichard   static_assert(is_same<decltype(v4), const float>::value, "");
3989a1d03eSRichard   static_assert(v4 == 1.0F, "");
4089a1d03eSRichard 
4189a1d03eSRichard   static constexpr auto v5 = 1.e0F; // OK.
4289a1d03eSRichard   static_assert(is_same<decltype(v5), const float>::value, "");
4389a1d03eSRichard   static_assert(v5 == 1.0F, "");
4489a1d03eSRichard 
4589a1d03eSRichard   // Long double
4689a1d03eSRichard 
4789a1d03eSRichard   static constexpr auto v6 = 1.l;
4889a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
4989a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v6 = 1.l;
5089a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
51*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: L{{$}}
5289a1d03eSRichard   // CHECK-FIXES: static constexpr auto v6 = 1.L;
5389a1d03eSRichard   static_assert(is_same<decltype(v6), const long double>::value, "");
5489a1d03eSRichard   static_assert(v6 == 1., "");
5589a1d03eSRichard 
5689a1d03eSRichard   static constexpr auto v7 = 1.e0l;
5789a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase
5889a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1.e0l;
5989a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
60*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: L{{$}}
6189a1d03eSRichard   // CHECK-FIXES: static constexpr auto v7 = 1.e0L;
6289a1d03eSRichard   static_assert(is_same<decltype(v7), const long double>::value, "");
6389a1d03eSRichard   static_assert(v7 == 1., "");
6489a1d03eSRichard 
6589a1d03eSRichard   static constexpr auto v8 = 1.L; // OK.
6689a1d03eSRichard   static_assert(is_same<decltype(v8), const long double>::value, "");
6789a1d03eSRichard   static_assert(v8 == 1., "");
6889a1d03eSRichard 
6989a1d03eSRichard   static constexpr auto v9 = 1.e0L; // OK.
7089a1d03eSRichard   static_assert(is_same<decltype(v9), const long double>::value, "");
7189a1d03eSRichard   static_assert(v9 == 1., "");
7289a1d03eSRichard 
7389a1d03eSRichard   // __float128
7489a1d03eSRichard 
7589a1d03eSRichard   static constexpr auto v10 = 1.q;
7689a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
7789a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v10 = 1.q;
7889a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
79*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: Q{{$}}
8089a1d03eSRichard   // CHECK-FIXES: static constexpr auto v10 = 1.Q;
8189a1d03eSRichard   static_assert(is_same<decltype(v10), const __float128>::value, "");
8289a1d03eSRichard   static_assert(v10 == 1., "");
8389a1d03eSRichard 
8489a1d03eSRichard   static constexpr auto v11 = 1.e0q;
8589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase
8689a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v11 = 1.e0q;
8789a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
88*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: Q{{$}}
8989a1d03eSRichard   // CHECK-FIXES: static constexpr auto v11 = 1.e0Q;
9089a1d03eSRichard   static_assert(is_same<decltype(v11), const __float128>::value, "");
9189a1d03eSRichard   static_assert(v11 == 1., "");
9289a1d03eSRichard 
9389a1d03eSRichard   static constexpr auto v12 = 1.Q; // OK.
9489a1d03eSRichard   static_assert(is_same<decltype(v12), const __float128>::value, "");
9589a1d03eSRichard   static_assert(v12 == 1., "");
9689a1d03eSRichard 
9789a1d03eSRichard   static constexpr auto v13 = 1.e0Q; // OK.
9889a1d03eSRichard   static_assert(is_same<decltype(v13), const __float128>::value, "");
9989a1d03eSRichard   static_assert(v13 == 1., "");
10089a1d03eSRichard }
10189a1d03eSRichard 
floating_point_complex_suffix()10289a1d03eSRichard void floating_point_complex_suffix() {
10389a1d03eSRichard   // _Complex, I
10489a1d03eSRichard 
10589a1d03eSRichard   static constexpr auto v14 = 1.i;
10689a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
10789a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1.i;
10889a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
109*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: I{{$}}
11089a1d03eSRichard   // CHECK-FIXES: static constexpr auto v14 = 1.I;
11189a1d03eSRichard   static_assert(is_same<decltype(v14), const _Complex double>::value, "");
11289a1d03eSRichard   static_assert(v14 == 1.I, "");
11389a1d03eSRichard 
11489a1d03eSRichard   static constexpr auto v15 = 1.e0i;
11589a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase
11689a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1.e0i;
11789a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
118*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: I{{$}}
11989a1d03eSRichard   // CHECK-FIXES: static constexpr auto v15 = 1.e0I;
12089a1d03eSRichard   static_assert(is_same<decltype(v15), const _Complex double>::value, "");
12189a1d03eSRichard   static_assert(v15 == 1.I, "");
12289a1d03eSRichard 
12389a1d03eSRichard   static constexpr auto v16 = 1.I; // OK.
12489a1d03eSRichard   static_assert(is_same<decltype(v16), const _Complex double>::value, "");
12589a1d03eSRichard   static_assert(v16 == 1.I, "");
12689a1d03eSRichard 
12789a1d03eSRichard   static constexpr auto v17 = 1.e0I; // OK.
12889a1d03eSRichard   static_assert(is_same<decltype(v17), const _Complex double>::value, "");
12989a1d03eSRichard   static_assert(v17 == 1.I, "");
13089a1d03eSRichard 
13189a1d03eSRichard   // _Complex, J
13289a1d03eSRichard 
13389a1d03eSRichard   static constexpr auto v18 = 1.j;
13489a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
13589a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v18 = 1.j;
13689a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
137*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: J{{$}}
13889a1d03eSRichard   // CHECK-FIXES: static constexpr auto v18 = 1.J;
13989a1d03eSRichard   static_assert(is_same<decltype(v18), const _Complex double>::value, "");
14089a1d03eSRichard   static_assert(v18 == 1.J, "");
14189a1d03eSRichard 
14289a1d03eSRichard   static constexpr auto v19 = 1.e0j;
14389a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase
14489a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto v19 = 1.e0j;
14589a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
146*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: J{{$}}
14789a1d03eSRichard   // CHECK-FIXES: static constexpr auto v19 = 1.e0J;
14889a1d03eSRichard   static_assert(is_same<decltype(v19), const _Complex double>::value, "");
14989a1d03eSRichard   static_assert(v19 == 1.J, "");
15089a1d03eSRichard 
15189a1d03eSRichard   static constexpr auto v20 = 1.J; // OK.
15289a1d03eSRichard   static_assert(is_same<decltype(v20), const _Complex double>::value, "");
15389a1d03eSRichard   static_assert(v20 == 1.J, "");
15489a1d03eSRichard 
15589a1d03eSRichard   static constexpr auto v21 = 1.e0J; // OK.
15689a1d03eSRichard   static_assert(is_same<decltype(v21), const _Complex double>::value, "");
15789a1d03eSRichard   static_assert(v21 == 1.J, "");
15889a1d03eSRichard }
15989a1d03eSRichard 
macros()16089a1d03eSRichard void macros() {
16189a1d03eSRichard #define PASSTHROUGH(X) X
16289a1d03eSRichard   static constexpr auto m0 = PASSTHROUGH(1.f);
16389a1d03eSRichard   // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase
16489a1d03eSRichard   // CHECK-MESSAGES-NEXT: static constexpr auto m0 = PASSTHROUGH(1.f);
16589a1d03eSRichard   // CHECK-MESSAGES-NEXT: ^ ~
166*f63155aaSTimm Bäder   // CHECK-MESSAGES-NEXT: F{{$}}
16789a1d03eSRichard   // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1.F);
16889a1d03eSRichard   static_assert(is_same<decltype(m0), const float>::value, "");
16989a1d03eSRichard   static_assert(m0 == 1.0F, "");
17089a1d03eSRichard }
171