1// RUN: %check_clang_tidy %s google-runtime-int %t
2
3long a();
4// CHECK-MESSAGES: [[@LINE-1]]:1: warning: consider replacing 'long' with 'int{{..}}'
5
6typedef unsigned long long uint64; // NOLINT
7
8long 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
12template <typename T>
13void tmpl() {
14 T i;
15}
16
17short 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
55void p(unsigned short port);
56
57void qux() {
58 short port;
59// CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'short' with 'int16'
60}
61
62struct some_value {};
63constexpr 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
70struct A { A& operator=(const A&); };
71class B { A a[0]; };
72
73void fff() {
74 B a, b;
75 a = b;
76}
77
78__attribute__((__format__ (__printf__, 1, 2)))
79void myprintf(const char* s, ...);
80
81void doprint_no_warning() {
82 uint64 foo = 23;
83 myprintf(s: "foo %lu %lu", (unsigned long)42, (unsigned long)foo);
84}
85
86void myprintf_no_attribute(const char* s, ...);
87
88void doprint_warning() {
89 uint64 foo = 23;
90 myprintf_no_attribute(s: "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

source code of clang-tools-extra/test/clang-tidy/checkers/google/runtime-int.cpp