Warning: That file was not part of the compilation database. It may have many parsing errors.

1// RUN: %check_clang_tidy %s llvmlibc-inline-function-decl %t
2
3#ifndef LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
4#define LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
5
6#define LIBC_INLINE inline
7
8namespace __llvm_libc {
9
10LIBC_INLINE int addi(int a, int b) {
11 return a + b;
12}
13
14LIBC_INLINE constexpr long addl(long a, long b) {
15 return a + b;
16}
17
18constexpr long long addll(long long a, long long b) {
19// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'addll' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
20// CHECK-FIXES: LIBC_INLINE constexpr long long addll(long long a, long long b) {
21 return a + b;
22}
23
24inline unsigned long addul(unsigned long a, unsigned long b) {
25// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'addul' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
26// CHECK-FIXES: LIBC_INLINE inline unsigned long addul(unsigned long a, unsigned long b) {
27 return a + b;
28}
29
30class MyClass {
31 int A;
32public:
33 MyClass() : A(123) {}
34 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'MyClass' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
35 // CHECK-FIXES: LIBC_INLINE MyClass() : A(123) {}
36
37 LIBC_INLINE MyClass(int V) : A(V) {}
38
39 constexpr operator int() const { return A; }
40 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator int' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
41 // CHECK-FIXES: LIBC_INLINE constexpr operator int() const { return A; }
42
43 LIBC_INLINE bool operator==(const MyClass &RHS) {
44 return RHS.A == A;
45 }
46
47 static int getVal(const MyClass &V) {
48 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'getVal' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
49 // CHECK-FIXES: LIBC_INLINE static int getVal(const MyClass &V) {
50 return V.A;
51 }
52
53 LIBC_INLINE static void setVal(MyClass &V, int A) {
54 V.A = A;
55 }
56
57 constexpr static int addInt(MyClass &V, int A) {
58 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'addInt' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
59 // CHECK-FIXES: LIBC_INLINE constexpr static int addInt(MyClass &V, int A) {
60 return V.A += A;
61 }
62
63 static LIBC_INLINE int mulInt(MyClass &V, int A) {
64 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'mulInt' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
65 return V.A *= A;
66 }
67};
68
69LIBC_INLINE void lambda() {
70// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
71// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
72// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
73// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
74 [](){};
75}
76
77namespace issue_62746 {
78
79void goodSimpleFunction();
80void badSimpleFunction();
81void badSimpleFunctionWrongLocation();
82
83LIBC_INLINE void goodSimpleFunction() {}
84
85inline void badSimpleFunction() {}
86// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
87// CHECK-FIXES: LIBC_INLINE inline void badSimpleFunction() {}
88
89void LIBC_INLINE badSimpleFunctionWrongLocation() {}
90// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
91
92template <typename T>
93void goodTemplateFunction();
94template <typename T>
95void badTemplateFunction();
96template <typename T>
97void badTemplateFunctionWrongLocation();
98
99template <typename T> LIBC_INLINE void goodTemplateFunction() {}
100
101template <typename T> inline void badTemplateFunction() {}
102// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
103// CHECK-FIXES: template <typename T> LIBC_INLINE inline void badTemplateFunction() {}
104
105template <typename T> void LIBC_INLINE badTemplateFunctionWrongLocation() {}
106// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
107
108template <typename... Ts>
109void goodVariadicFunction();
110template <typename... Ts>
111void badVariadicFunction();
112template <typename... Ts>
113void badVariadicFunctionWrongLocation();
114
115template <typename... Ts> LIBC_INLINE void goodVariadicFunction() {}
116
117template <typename... Ts> inline void badVariadicFunction() {}
118// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
119// CHECK-FIXES: template <typename... Ts> LIBC_INLINE inline void badVariadicFunction() {}
120
121template <typename... Ts> void LIBC_INLINE badVariadicFunctionWrongLocation() {}
122// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
123// CHECK-FIXES: template <typename... Ts> LIBC_INLINE void LIBC_INLINE badVariadicFunctionWrongLocation() {}
124
125struct NoTemplate {
126 void goodNoTemplate();
127 void badNoTemplate();
128 void badNoTemplateWrongLocation();
129
130 template <typename T>
131 void goodNestedTemplate();
132 template <typename T>
133 void badNestedTemplate();
134 template <typename T>
135 void badNestedTemplateWrongLocation();
136
137 template <typename... Ts>
138 void goodVariadicTemplate();
139 template <typename... Ts>
140 void badVariadicTemplate();
141 template <typename... Ts>
142 void badVariadicTemplateWrongLocation();
143
144};
145
146LIBC_INLINE void NoTemplate::goodNoTemplate() {}
147
148inline void NoTemplate::badNoTemplate() {}
149// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
150// CHECK-FIXES: LIBC_INLINE inline void NoTemplate::badNoTemplate() {}
151
152void LIBC_INLINE NoTemplate::badNoTemplateWrongLocation() {}
153// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
154// CHECK-FIXES: LIBC_INLINE void LIBC_INLINE NoTemplate::badNoTemplateWrongLocation() {}
155
156template <typename T> LIBC_INLINE void NoTemplate::goodNestedTemplate() {}
157
158template <typename T> inline void NoTemplate::badNestedTemplate() {}
159// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
160// CHECK-FIXES: template <typename T> LIBC_INLINE inline void NoTemplate::badNestedTemplate() {}
161
162template <typename T> void LIBC_INLINE NoTemplate::badNestedTemplateWrongLocation() {}
163// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
164// CHECK-FIXES: template <typename T> LIBC_INLINE void LIBC_INLINE NoTemplate::badNestedTemplateWrongLocation() {}
165
166template <typename... Ts> LIBC_INLINE void NoTemplate::goodVariadicTemplate() {}
167
168template <typename... Ts> void inline NoTemplate::badVariadicTemplate() {}
169// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
170// CHECK-FIXES: template <typename... Ts> LIBC_INLINE void inline NoTemplate::badVariadicTemplate() {}
171
172template <typename... Ts> void LIBC_INLINE NoTemplate::badVariadicTemplateWrongLocation() {}
173// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
174
175template <typename T>
176struct SimpleTemplate {
177 void goodSimpleTemplate();
178 void badSimpleTemplate();
179 void badSimpleTemplateWrongLocation();
180
181 template <typename U>
182 void goodNestedTemplate();
183 template <typename U>
184 void badNestedTemplate();
185 template <typename U>
186 void badNestedTemplateWrongLocation();
187
188 template <typename... Ts>
189 void goodNestedVariadicTemplate();
190 template <typename... Ts>
191 void badNestedVariadicTemplate();
192 template <typename... Ts>
193 void badNestedVariadicTemplateWrongLocation();
194};
195
196template <typename T> LIBC_INLINE void SimpleTemplate<T>::goodSimpleTemplate() {}
197
198template <typename T> inline void SimpleTemplate<T>::badSimpleTemplate() {}
199// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badSimpleTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
200// CHECK-FIXES: template <typename T> LIBC_INLINE inline void SimpleTemplate<T>::badSimpleTemplate() {}
201
202template <typename T> void LIBC_INLINE SimpleTemplate<T>::badSimpleTemplateWrongLocation() {}
203// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badSimpleTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
204
205template <typename T> template <typename U> LIBC_INLINE void SimpleTemplate<T>::goodNestedTemplate() {}
206
207template <typename T> template <typename U> inline void SimpleTemplate<T>::badNestedTemplate() {}
208// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
209// CHECK-FIXES: template <typename T> template <typename U> LIBC_INLINE inline void SimpleTemplate<T>::badNestedTemplate() {}
210
211template <typename T> template <typename U> void LIBC_INLINE SimpleTemplate<T>::badNestedTemplateWrongLocation() {}
212// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
213
214template <typename T> template <typename... Ts> LIBC_INLINE void SimpleTemplate<T>::goodNestedVariadicTemplate() {}
215
216template <typename T> template <typename... Ts> inline void SimpleTemplate<T>::badNestedVariadicTemplate() {}
217// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
218// CHECK-FIXES: template <typename T> template <typename... Ts> LIBC_INLINE inline void SimpleTemplate<T>::badNestedVariadicTemplate() {}
219
220template <typename T> template <typename... Ts> void LIBC_INLINE SimpleTemplate<T>::badNestedVariadicTemplateWrongLocation() {}
221// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
222
223template <typename... Ts>
224struct VariadicTemplate {
225 void goodVariadicTemplate();
226 void badVariadicTemplate();
227 void badVariadicTemplateWrongLocation();
228
229 template <typename U>
230 void goodNestedTemplate();
231 template <typename U>
232 void badNestedTemplate();
233 template <typename U>
234 void badNestedTemplateWrongLocation();
235
236 template <typename... Us>
237 void goodNestedVariadicTemplate();
238 template <typename... Us>
239 void badNestedVariadicTemplate();
240 template <typename... Us>
241 void badNestedVariadicTemplateWrongLocation();
242};
243
244template <typename... Ts> LIBC_INLINE void VariadicTemplate<Ts...>::goodVariadicTemplate() {}
245
246template <typename... Ts> inline void VariadicTemplate<Ts...>::badVariadicTemplate() {}
247// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
248// CHECK-FIXES: template <typename... Ts> LIBC_INLINE inline void VariadicTemplate<Ts...>::badVariadicTemplate() {}
249
250template <typename... Ts> void LIBC_INLINE VariadicTemplate<Ts...>::badVariadicTemplateWrongLocation() {}
251// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
252
253template <typename... Ts> template <typename U> LIBC_INLINE void VariadicTemplate<Ts...>::goodNestedTemplate() {}
254
255template <typename... Ts> template <typename U> inline void VariadicTemplate<Ts...>::badNestedTemplate() {}
256// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
257// CHECK-FIXES: template <typename... Ts> template <typename U> LIBC_INLINE inline void VariadicTemplate<Ts...>::badNestedTemplate() {}
258
259template <typename... Ts> template <typename U> void LIBC_INLINE VariadicTemplate<Ts...>::badNestedTemplateWrongLocation() {}
260// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
261
262template <typename... Ts> template <typename... Us> LIBC_INLINE void VariadicTemplate<Ts...>::goodNestedVariadicTemplate() {}
263
264template <typename... Ts> template <typename... Us> inline void VariadicTemplate<Ts...>::badNestedVariadicTemplate() {}
265// CHECK-MESSAGES: :[[@LINE-1]]:53: warning: 'badNestedVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
266// CHECK-FIXES: template <typename... Ts> template <typename... Us> LIBC_INLINE inline void VariadicTemplate<Ts...>::badNestedVariadicTemplate() {}
267
268template <typename... Ts> template <typename... Us> void LIBC_INLINE VariadicTemplate<Ts...>::badNestedVariadicTemplateWrongLocation() {}
269// CHECK-MESSAGES: :[[@LINE-1]]:53: warning: 'badNestedVariadicTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
270
271template <typename T>
272void goodWeirdFormatting();
273template <typename T>
274void badWeirdFormatting();
275
276template <typename T>LIBC_INLINE void goodWeirdFormatting() {}
277
278template <typename T>void LIBC_INLINE badWeirdFormatting() {}
279// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'badWeirdFormatting' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
280
281
282template <unsigned int NumberOfBits> struct HasMemberAndTemplate {
283 char Data[NumberOfBits];
284
285 void explicitFunction() {}
286// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'explicitFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
287// CHECK-FIXES: LIBC_INLINE void explicitFunction() {}
288};
289
290static auto instanceOfStruct = HasMemberAndTemplate<16>();
291
292struct HasMemberAndExplicitDefault {
293 int TrivialMember;
294
295 HasMemberAndExplicitDefault() = default;
296// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'HasMemberAndExplicitDefault' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
297// CHECK-FIXES: LIBC_INLINE HasMemberAndExplicitDefault() = default;
298
299 ~HasMemberAndExplicitDefault() = delete;
300};
301
302
303} // namespace issue_62746
304
305} // namespace __llvm_libc
306
307#endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
308

Warning: That file was not part of the compilation database. It may have many parsing errors.

source code of clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp