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 // FIXME: This shouldn't warn, as UD-literal operators require one of a handful
63 // of types as an argument.
64 struct some_value {};
65 constexpr some_value operator"" _some_literal(unsigned long long int i);
66 // CHECK-MESSAGES: [[@LINE-1]]:47: warning: consider replacing 'unsigned long long'
67 
68 struct A { A& operator=(const A&); };
69 class B { A a[0]; };
70 
fff()71 void fff() {
72   B a, b;
73   a = b;
74 }
75 
76 __attribute__((__format__ (__printf__, 1, 2)))
77 void myprintf(const char* s, ...);
78 
doprint_no_warning()79 void doprint_no_warning() {
80   uint64 foo = 23;
81   myprintf("foo %lu %lu", (unsigned long)42, (unsigned long)foo);
82 }
83 
84 void myprintf_no_attribute(const char* s, ...);
85 
doprint_warning()86 void doprint_warning() {
87   uint64 foo = 23;
88   myprintf_no_attribute("foo %lu %lu", (unsigned long)42, (unsigned long)foo);
89 // CHECK-MESSAGES: [[@LINE-1]]:41: warning: consider replacing 'unsigned long'
90 // CHECK-MESSAGES: [[@LINE-2]]:60: warning: consider replacing 'unsigned long'
91 }
92