1 // RUN: %check_clang_tidy %s google-runtime-int %t
2
3 long a();
4 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: consider replacing 'long' with 'int{{..}}'
5
6 typedef unsigned long long uint64; // NOLINT
7
8 long b(long = 1);
9 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: consider replacing 'long' with 'int{{..}}'
10 // CHECK-MESSAGES: [[@LINE-2]]:8: warning: consider replacing 'long' with 'int{{..}}'
11
12 template <typename T>
tmpl()13 void tmpl() {
14 T i;
15 }
16
bar(const short,unsigned short)17 short bar(const short, unsigned short) {
18 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: consider replacing 'short' with 'int16'
19 // CHECK-MESSAGES: [[@LINE-2]]:17: warning: consider replacing 'short' with 'int16'
20 // CHECK-MESSAGES: [[@LINE-3]]:24: warning: consider replacing 'unsigned short' with 'uint16'
21 long double foo = 42;
22 uint64 qux = 42;
23 unsigned short port;
24
25 const unsigned short bar = 0;
26 // CHECK-MESSAGES: [[@LINE-1]]:9: warning: consider replacing 'unsigned short' with 'uint16'
27 long long *baar;
28 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'long long' with 'int64'
29 const unsigned short &bara = bar;
30 // CHECK-MESSAGES: [[@LINE-1]]:9: warning: consider replacing 'unsigned short' with 'uint16'
31 long const long moo = 1;
32 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'long long' with 'int64'
33 long volatile long wat = 42;
34 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'long long' with 'int64'
35 unsigned long y;
36 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'unsigned long' with 'uint{{..}}'
37 unsigned long long **const *tmp;
38 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'unsigned long long' with 'uint64'
39 unsigned long long **const *&z = tmp;
40 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'unsigned long long' with 'uint64'
41 unsigned short porthole;
42 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'unsigned short' with 'uint16'
43
44 uint64 cast = (short)42;
45 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: consider replacing 'short' with 'int16'
46
47 #define l long
48 l x;
49
50 tmpl<short>();
51 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: consider replacing 'short' with 'int16'
52 return 0;
53 }
54
55 void p(unsigned short port);
56
qux()57 void qux() {
58 short port;
59 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'short' with 'int16'
60 }
61
62 struct some_value {};
operator ""_some_literal(unsigned long long int i)63 constexpr some_value operator"" _some_literal(unsigned long long int i)
64 {
65 short j;
66 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'short' with 'int16'
67 return some_value();
68 }
69
70 struct A { A& operator=(const A&); };
71 class B { A a[0]; };
72
fff()73 void fff() {
74 B a, b;
75 a = b;
76 }
77
78 __attribute__((__format__ (__printf__, 1, 2)))
79 void myprintf(const char* s, ...);
80
doprint_no_warning()81 void doprint_no_warning() {
82 uint64 foo = 23;
83 myprintf("foo %lu %lu", (unsigned long)42, (unsigned long)foo);
84 }
85
86 void myprintf_no_attribute(const char* s, ...);
87
doprint_warning()88 void doprint_warning() {
89 uint64 foo = 23;
90 myprintf_no_attribute("foo %lu %lu", (unsigned long)42, (unsigned long)foo);
91 // CHECK-MESSAGES: [[@LINE-1]]:41: warning: consider replacing 'unsigned long'
92 // CHECK-MESSAGES: [[@LINE-2]]:60: warning: consider replacing 'unsigned long'
93 }
94