• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %S -fms-extensions
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 %S -fms-extensions
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 %S -fms-extensions
5 
6 #include "readability-uppercase-literal-suffix.h"
7 
integer_suffix()8 void 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   // i32
19 
20   static constexpr auto v3 = 1i32;
21   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i32', which is not uppercase
22   // CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1i32;
23   // CHECK-MESSAGES-NEXT: ^~
24   // CHECK-MESSAGES-NEXT: {{^ *}}I32{{$}}
25   // CHECK-FIXES: static constexpr auto v3 = 1I32;
26   static_assert(is_same<decltype(v3), const int>::value, "");
27   static_assert(v3 == 1I32, "");
28 
29   static constexpr auto v4 = 1I32; // OK.
30   static_assert(is_same<decltype(v4), const int>::value, "");
31   static_assert(v4 == 1I32, "");
32 
33   // i64
34 
35   static constexpr auto v5 = 1i64;
36   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i64', which is not uppercase
37   // CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1i64;
38   // CHECK-MESSAGES-NEXT: ^~
39   // CHECK-MESSAGES-NEXT: {{^ *}}I64{{$}}
40   // CHECK-FIXES: static constexpr auto v5 = 1I64;
41   static_assert(is_same<decltype(v5), const long int>::value, "");
42   static_assert(v5 == 1I64, "");
43 
44   static constexpr auto v6 = 1I64; // OK.
45   static_assert(is_same<decltype(v6), const long int>::value, "");
46   static_assert(v6 == 1I64, "");
47 
48   // i16
49 
50   static constexpr auto v7 = 1i16;
51   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i16', which is not uppercase
52   // CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1i16;
53   // CHECK-MESSAGES-NEXT: ^~
54   // CHECK-MESSAGES-NEXT: {{^ *}}I16{{$}}
55   // CHECK-FIXES: static constexpr auto v7 = 1I16;
56   static_assert(is_same<decltype(v7), const short>::value, "");
57   static_assert(v7 == 1I16, "");
58 
59   static constexpr auto v8 = 1I16; // OK.
60   static_assert(is_same<decltype(v8), const short>::value, "");
61   static_assert(v8 == 1I16, "");
62 
63   // i8
64 
65   static constexpr auto v9 = 1i8;
66   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'i8', which is not uppercase
67   // CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1i8;
68   // CHECK-MESSAGES-NEXT: ^~
69   // CHECK-MESSAGES-NEXT: {{^ *}}I8{{$}}
70   // CHECK-FIXES: static constexpr auto v9 = 1I8;
71   static_assert(is_same<decltype(v9), const char>::value, "");
72   static_assert(v9 == 1I8, "");
73 
74   static constexpr auto v10 = 1I8; // OK.
75   static_assert(is_same<decltype(v10), const char>::value, "");
76   static_assert(v10 == 1I8, "");
77 }
78