1 | // RUN: %check_clang_tidy %s modernize-redundant-void-arg %t |
2 | |
3 | #define NULL 0 |
4 | |
5 | int foo(); |
6 | |
7 | void bar(); |
8 | |
9 | void bar2(); |
10 | |
11 | extern "C" void ecfoo(void); |
12 | |
13 | extern "C" void ecfoo(void) { |
14 | } |
15 | |
16 | extern int i; |
17 | |
18 | int j = 1; |
19 | |
20 | int foo(void) { |
21 | // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant void argument list in function definition [modernize-redundant-void-arg] |
22 | // CHECK-FIXES: {{^}}int foo() {{{$}} |
23 | return 0; |
24 | } |
25 | |
26 | typedef unsigned int my_uint; |
27 | |
28 | typedef void my_void; |
29 | |
30 | // A function taking void and returning a pointer to function taking void |
31 | // and returning int. |
32 | int (*returns_fn_void_int(void))(void); |
33 | // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function declaration |
34 | // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function declaration |
35 | // CHECK-FIXES: {{^}}int (*returns_fn_void_int())();{{$}} |
36 | |
37 | typedef int (*returns_fn_void_int_t(void))(void); |
38 | // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: {{.*}} in typedef |
39 | // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: {{.*}} in typedef |
40 | // CHECK-FIXES: {{^}}typedef int (*returns_fn_void_int_t())();{{$}} |
41 | |
42 | // Should work for type aliases as well as typedef. |
43 | using returns_fn_void_int_t2 = int (*(void))(void); |
44 | // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: {{.*}} in type alias |
45 | // CHECK-MESSAGES: :[[@LINE-2]]:46: warning: {{.*}} in type alias |
46 | // CHECK-FIXES: {{^}}using returns_fn_void_int_t2 = int (*())();{{$}} |
47 | |
48 | int (*returns_fn_void_int(void))(void) { |
49 | // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function definition |
50 | // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function definition |
51 | // CHECK-FIXES: {{^}}int (*returns_fn_void_int())() {{{$}} |
52 | return nullptr; |
53 | } |
54 | |
55 | // A function taking void and returning a pointer to a function taking void |
56 | // and returning a pointer to a function taking void and returning void. |
57 | void (*(*returns_fn_returns_fn_void_void(void))(void))(void); |
58 | // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function declaration |
59 | // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function declaration |
60 | // CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function declaration |
61 | // CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())();{{$}} |
62 | |
63 | typedef void (*(*returns_fn_returns_fn_void_void_t(void))(void))(void); |
64 | // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: {{.*}} in typedef |
65 | // CHECK-MESSAGES: :[[@LINE-2]]:59: warning: {{.*}} in typedef |
66 | // CHECK-MESSAGES: :[[@LINE-3]]:66: warning: {{.*}} in typedef |
67 | // CHECK-FIXES: {{^}}typedef void (*(*returns_fn_returns_fn_void_void_t())())();{{$}} |
68 | |
69 | void (*(*returns_fn_returns_fn_void_void(void))(void))(void) { |
70 | // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function definition |
71 | // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function definition |
72 | // CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function definition |
73 | // CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())() {{{$}} |
74 | return nullptr; |
75 | } |
76 | |
77 | void bar(void) { |
78 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: {{.*}} in function definition |
79 | // CHECK-FIXES: {{^}}void bar() {{{$}} |
80 | } |
81 | |
82 | void op_fn(int i) { |
83 | } |
84 | |
85 | class gronk { |
86 | public: |
87 | gronk(); |
88 | ~gronk(); |
89 | |
90 | void foo(); |
91 | void bar(); |
92 | void bar2 |
93 | (); |
94 | void operation(int i) { } |
95 | |
96 | private: |
97 | int m_i; |
98 | int *m_pi; |
99 | float m_f; |
100 | float *m_pf; |
101 | double m_d; |
102 | double *m_pd; |
103 | |
104 | void (*f1)(void); |
105 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in field declaration |
106 | // CHECK-FIXES: {{^ }}void (*f1)();{{$}} |
107 | |
108 | void (*op)(int i); |
109 | |
110 | void (gronk::*p1)(void); |
111 | // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in field declaration |
112 | // CHECK-FIXES: {{^ }}void (gronk::*p1)();{{$}} |
113 | |
114 | int (gronk::*p_mi); |
115 | |
116 | void (gronk::*p2)(int); |
117 | |
118 | void (*(*returns_fn_returns_fn_void_void(void))(void))(void); |
119 | // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: {{.*}} in function declaration |
120 | // CHECK-MESSAGES: :[[@LINE-2]]:51: warning: {{.*}} in function declaration |
121 | // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: {{.*}} in function declaration |
122 | // CHECK-FIXES: {{^}} void (*(*returns_fn_returns_fn_void_void())())();{{$}} |
123 | |
124 | void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)(void))(void))(void); |
125 | // CHECK-MESSAGES: :[[@LINE-1]]:58: warning: {{.*}} in field declaration |
126 | // CHECK-MESSAGES: :[[@LINE-2]]:65: warning: {{.*}} in field declaration |
127 | // CHECK-MESSAGES: :[[@LINE-3]]:72: warning: {{.*}} in field declaration |
128 | // CHECK-FIXES: {{^}} void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)())())();{{$}} |
129 | }; |
130 | |
131 | int i; |
132 | int *pi; |
133 | void *pv = (void *) pi; |
134 | float f; |
135 | float *fi; |
136 | double d; |
137 | double *pd; |
138 | |
139 | void (*f1)(void); |
140 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration |
141 | // CHECK-FIXES: {{^}}void (*f1)();{{$}} |
142 | |
143 | void (*f2)(void) = nullptr; |
144 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration with initializer |
145 | // CHECK-FIXES: {{^}}void (*f2)() = nullptr;{{$}} |
146 | |
147 | void (*f2b)(void)(nullptr); |
148 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer |
149 | // CHECK-FIXES: {{^}}void (*f2b)()(nullptr);{{$}} |
150 | |
151 | void (*f2c)(void){nullptr}; |
152 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer |
153 | // CHECK-FIXES: {{^}}void (*f2c)(){nullptr};{{$}} |
154 | |
155 | void (*f2d)(void) = NULL; |
156 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer |
157 | // CHECK-FIXES: {{^}}void (*f2d)() = NULL;{{$}} |
158 | |
159 | void (*f2e)(void)(NULL); |
160 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer |
161 | // CHECK-FIXES: {{^}}void (*f2e)()(NULL);{{$}} |
162 | |
163 | void (*f2f)(void){NULL}; |
164 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer |
165 | // CHECK-FIXES: {{^}}void (*f2f)(){NULL};{{$}} |
166 | |
167 | void (*f3)(void) = bar; |
168 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration with initializer |
169 | // CHECK-FIXES: {{^}}void (*f3)() = bar;{{$}} |
170 | |
171 | void (*o1)(int i); |
172 | void (*o2)(int i) = nullptr; |
173 | void (*o3)(int i)(nullptr); |
174 | void (*o4)(int i){nullptr}; |
175 | void (*o5)(int i) = NULL; |
176 | void (*o6)(int i)(NULL); |
177 | void (*o7)(int i){NULL}; |
178 | void (*o8)(int i) = op_fn; |
179 | |
180 | void (*fa)(); |
181 | |
182 | void (*fb)() = nullptr; |
183 | |
184 | void (*fc)() = bar; |
185 | |
186 | typedef void (function_ptr)(void); |
187 | // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: {{.*}} in typedef |
188 | // CHECK-FIXES: {{^}}typedef void (function_ptr)();{{$}} |
189 | |
190 | // intentionally not LLVM style to check preservation of whitespace |
191 | typedef void (function_ptr2) |
192 | ( |
193 | void |
194 | ); |
195 | // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: {{.*}} in typedef |
196 | // CHECK-FIXES: {{^typedef void \(function_ptr2\)$}} |
197 | // CHECK-FIXES-NEXT: {{^ \($}} |
198 | // CHECK-FIXES-NEXT: {{^ $}} |
199 | // CHECK-FIXES-NEXT: {{^ \);$}} |
200 | |
201 | // intentionally not LLVM style to check preservation of whitespace |
202 | // clang-format off |
203 | typedef |
204 | void |
205 | ( |
206 | * |
207 | ( |
208 | * |
209 | returns_fn_returns_fn_void_void_t2 |
210 | ( |
211 | void |
212 | ) |
213 | ) |
214 | ( |
215 | void |
216 | ) |
217 | ) |
218 | ( |
219 | void |
220 | ) |
221 | ; |
222 | // CHECK-MESSAGES: :[[@LINE-11]]:1: warning: {{.*}} in typedef |
223 | // CHECK-MESSAGES: :[[@LINE-8]]:1: warning: {{.*}} in typedef |
224 | // CHECK-MESSAGES: :[[@LINE-5]]:1: warning: {{.*}} in typedef |
225 | // CHECK-FIXES: {{^typedef$}} |
226 | // CHECK-FIXES-NEXT: {{^void$}} |
227 | // CHECK-FIXES-NEXT: {{^\($}} |
228 | // CHECK-FIXES-NEXT: {{^\*$}} |
229 | // CHECK-FIXES-NEXT: {{^\($}} |
230 | // CHECK-FIXES-NEXT: {{^\*$}} |
231 | // CHECK-FIXES-NEXT: {{^returns_fn_returns_fn_void_void_t2$}} |
232 | // CHECK-FIXES-NEXT: {{^\($}} |
233 | // CHECK-FIXES-NOT: {{[^ ]}} |
234 | // CHECK-FIXES: {{^\)$}} |
235 | // CHECK-FIXES-NEXT: {{^\)$}} |
236 | // CHECK-FIXES-NEXT: {{^\($}} |
237 | // CHECK-FIXES-NOT: {{[^ ]}} |
238 | // CHECK-FIXES: {{^\)$}} |
239 | // CHECK-FIXES-NEXT: {{^\)$}} |
240 | // CHECK-FIXES-NEXT: {{^\($}} |
241 | // CHECK-FIXES-NOT: {{[^ ]}} |
242 | // CHECK-FIXES: {{^\)$}} |
243 | // CHECK-FIXES-NEXT: {{^;$}} |
244 | // clang-format on |
245 | |
246 | void (gronk::*p1)(void); |
247 | // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration |
248 | // CHECK-FIXES: {{^}}void (gronk::*p1)();{{$}} |
249 | |
250 | void (gronk::*p2)(void) = &gronk::foo; |
251 | // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration with initializer |
252 | // CHECK-FIXES: {{^}}void (gronk::*p2)() = &gronk::foo;{{$}} |
253 | |
254 | typedef void (gronk::*member_function_ptr)(void); |
255 | // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: {{.*}} in typedef |
256 | // CHECK-FIXES: {{^}}typedef void (gronk::*member_function_ptr)();{{$}} |
257 | |
258 | // intentionally not LLVM style to check preservation of whitespace |
259 | typedef void (gronk::*member_function_ptr2) |
260 | ( |
261 | void |
262 | ); |
263 | // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: {{.*}} in typedef |
264 | // CHECK-FIXES: {{^typedef void \(gronk::\*member_function_ptr2\)$}} |
265 | // CHECK-FIXES-NEXT: {{^ \($}} |
266 | // CHECK-FIXES-NEXT: {{^ $}} |
267 | // CHECK-FIXES-NEXT: {{^ \);$}} |
268 | |
269 | void gronk::foo() { |
270 | void (*f1)(void) = &::bar; |
271 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer |
272 | // CHECK-FIXES: {{^ }}void (*f1)() = &::bar;{{$}} |
273 | |
274 | void (*f2)(void); |
275 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration |
276 | // CHECK-FIXES: {{^ }}void (*f2)();{{$}} |
277 | |
278 | // intentionally not LLVM style to check preservation of whitespace |
279 | void (*f3) |
280 | ( |
281 | void |
282 | ); |
283 | // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: {{.*}} in variable declaration |
284 | // CHECK-FIXES: {{^ }}void (*f3){{$}} |
285 | // CHECK-FIXES-NEXT: {{^ \($}} |
286 | // CHECK-FIXES-NEXT: {{^ $}} |
287 | // CHECK-FIXES-NEXT: {{^ \);$}} |
288 | } |
289 | |
290 | void gronk::bar(void) { |
291 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} in function definition |
292 | // CHECK-FIXES: {{^}}void gronk::bar() {{{$}} |
293 | void (gronk::*p3)(void) = &gronk::foo; |
294 | // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in variable declaration with initializer |
295 | // CHECK-FIXES: {{^ }}void (gronk::*p3)() = &gronk::foo;{{$}} |
296 | |
297 | void (gronk::*p4)(void); |
298 | // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in variable declaration |
299 | // CHECK-FIXES: {{^ }}void (gronk::*p4)();{{$}} |
300 | |
301 | // intentionally not LLVM style to check preservation of whitespace |
302 | void (gronk::*p5) |
303 | ( |
304 | void |
305 | ); |
306 | // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: {{.*}} in variable declaration |
307 | // CHECK-FIXES: {{^ }}void (gronk::*p5){{$}} |
308 | // CHECK-FIXES-NEXT: {{^ \($}} |
309 | // CHECK-FIXES-NExT: {{^ $}} |
310 | // CHECK-FIXES-NExT: {{^ \);$}} |
311 | } |
312 | |
313 | // intentionally not LLVM style to check preservation of whitespace |
314 | void gronk::bar2 |
315 | ( |
316 | void |
317 | ) |
318 | // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: {{.*}} in function definition |
319 | // CHECK-FIXES: {{^void gronk::bar2$}} |
320 | // CHECK-FIXES-NEXT: {{^ \($}} |
321 | // CHECK-FIXES-NEXT: {{^ $}} |
322 | // CHECK-FIXES-NEXT: {{^ \)$}} |
323 | { |
324 | } |
325 | |
326 | gronk::gronk(void) |
327 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in function definition |
328 | // CHECK-FIXES: {{^}}gronk::gronk(){{$}} |
329 | : f1(nullptr), |
330 | p1(nullptr) { |
331 | } |
332 | |
333 | gronk::~gronk(void) { |
334 | // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} in function definition |
335 | // CHECK-FIXES: {{^}}gronk::~gronk() {{{$}} |
336 | } |
337 | |
338 | class nutter { |
339 | public: |
340 | nutter(); |
341 | }; |
342 | |
343 | nutter::nutter(void) { |
344 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition |
345 | // CHECK-FIXES: {{^}}nutter::nutter() {{{$}} |
346 | void (*f3)(void) = static_cast<void (*)(void)>(0); |
347 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer |
348 | // CHECK-MESSAGES: :[[@LINE-2]]:43: warning: {{.*}} in named cast |
349 | // CHECK-FIXES: void (*f3)() = static_cast<void (*)()>(0);{{$}} |
350 | |
351 | void (*f4)(void) = (void (*)(void)) 0; |
352 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer |
353 | // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: {{.*}} in cast expression |
354 | // CHECK-FIXES: void (*f4)() = (void (*)()) 0;{{$}} |
355 | |
356 | void (*f5)(void) = reinterpret_cast<void (*)(void)>(0); |
357 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer |
358 | // CHECK-MESSAGES: :[[@LINE-2]]:48: warning: {{.*}} in named cast |
359 | // CHECK-FIXES: void (*f5)() = reinterpret_cast<void (*)()>(0);{{$}} |
360 | |
361 | // intentionally not LLVM style to check preservation of whitespace |
362 | void (*f6)(void) = static_cast<void (*) |
363 | ( |
364 | void |
365 | )>(0); |
366 | // CHECK-MESSAGES: :[[@LINE-4]]:14: warning: {{.*}} in variable declaration with initializer |
367 | // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: {{.*}} in named cast |
368 | // CHECK-FIXES: {{^ }}void (*f6)() = static_cast<void (*){{$}} |
369 | // CHECK-FIXES-NEXT: {{^ \($}} |
370 | // CHECK-FIXES-NEXT: {{^ $}} |
371 | // CHECK-FIXES-NEXT: {{^ }})>(0);{{$}} |
372 | |
373 | // intentionally not LLVM style to check preservation of whitespace |
374 | void (*f7)(void) = (void (*) |
375 | ( |
376 | void |
377 | )) 0; |
378 | // CHECK-MESSAGES: :[[@LINE-4]]:14: warning: {{.*}} in variable declaration with initializer |
379 | // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: {{.*}} in cast expression |
380 | // CHECK-FIXES: {{^ }}void (*f7)() = (void (*){{$}} |
381 | // CHECK-FIXES-NEXT: {{^ \($}} |
382 | // CHECK-FIXES-NEXT: {{^ $}} |
383 | // CHECK-FIXES-NEXT: {{^ \)\) 0;$}} |
384 | |
385 | // intentionally not LLVM style to check preservation of whitespace |
386 | void (*f8)(void) = reinterpret_cast<void (*) |
387 | ( |
388 | void |
389 | )>(0); |
390 | // CHECK-MESSAGES: :[[@LINE-4]]:14: warning: {{.*}} in variable declaration with initializer |
391 | // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: {{.*}} in named cast |
392 | // CHECK-FIXES: {{^ }}void (*f8)() = reinterpret_cast<void (*){{$}} |
393 | // CHECK-FIXES-NEXT: {{^ \($}} |
394 | // CHECK-FIXES-NEXT: {{^ $}} |
395 | // CHECK-FIXES-NEXT: {{^ \)>\(0\);$}} |
396 | |
397 | void (*o1)(int) = static_cast<void (*)(int)>(0); |
398 | void (*o2)(int) = (void (*)(int)) 0; |
399 | void (*o3)(int) = reinterpret_cast<void (*)(int)>(0); |
400 | } |
401 | |
402 | class generator { |
403 | public: |
404 | int operator()(void) { return 1; } |
405 | // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: {{.*}} in function definition |
406 | // CHECK-FIXES: {{^ }}int operator()() { return 1; }{{$}} |
407 | }; |
408 | |
409 | void test_lambda_functions() { |
410 | auto lamb_duh = [](void (*fn)(void)) { (*fn)(); }; |
411 | // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: {{.*}} in variable declaration |
412 | // CHECK-FIXES: {{^ }}auto lamb_duh = [](void (*fn)()) { (*fn)(); };{{$}} |
413 | |
414 | auto lambda_generator = [](void) { return 1; }; |
415 | // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: {{.*}} in lambda expression |
416 | // CHECK-FIXES: {{^ }}auto lambda_generator = []() { return 1; };{{$}} |
417 | |
418 | auto gen2 = []() { return 1; }; |
419 | |
420 | auto gen3 = []{ return 1; }; |
421 | |
422 | auto void_returner = [](void) -> void (*)(void) { return f1; }; |
423 | // CHECK-MESSAGES: [[@LINE-1]]:27: warning: {{.*}} in lambda expression |
424 | // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression |
425 | // CHECK-FIXES: {{^ }}auto void_returner = []() -> void (*)() { return f1; };{{$}} |
426 | } |
427 | |
428 | #define M(x) x |
429 | |
430 | M(void inmacro(void) {}) |
431 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition |
432 | // CHECK-FIXES: M(void inmacro() {}) |
433 | |
434 | #define F(A, B) \ |
435 | struct F_##A##_##B { \ |
436 | F_##A##_##B(void); \ |
437 | }; \ |
438 | F_##A##_##B::F_##A##_##B(void) |
439 | |
440 | F(Foo, Bar) { |
441 | |
442 | } |
443 | |
444 | struct DefinitionWithNoBody { |
445 | DefinitionWithNoBody(void) = delete; |
446 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition |
447 | // CHECK-FIXES: DefinitionWithNoBody() = delete; |
448 | }; |
449 | |
450 | |
451 | |
452 | #define BODY {} |
453 | #define LAMBDA1 [](void){} |
454 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
455 | // CHECK-FIXES: LAMBDA1 [](){} |
456 | |
457 | #define LAMBDA2 [](void)BODY |
458 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
459 | // CHECK-FIXES: LAMBDA2 []()BODY |
460 | |
461 | #define LAMBDA3(captures, args, body) captures args body |
462 | #define WRAP(...) __VA_ARGS__ |
463 | |
464 | #define LAMBDA4 (void)LAMBDA3([],(void),BODY) |
465 | // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
466 | // CHECK-FIXES: LAMBDA4 (void)LAMBDA3([],(),BODY) |
467 | |
468 | #define LAMBDA5 []() -> void (*)(void) {return BODY;} |
469 | // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
470 | // CHECK-FIXES: LAMBDA5 []() -> void (*)() {return BODY;} |
471 | void lambda_expression_with_macro_test(){ |
472 | (void)LAMBDA1; |
473 | (void)LAMBDA2; |
474 | (void)LAMBDA3([], (void), BODY); |
475 | // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
476 | // CHECK-FIXES: (void)LAMBDA3([], (), BODY); |
477 | |
478 | LAMBDA4; |
479 | LAMBDA5; |
480 | WRAP((void)WRAP(WRAP(LAMBDA3(WRAP([]), WRAP((void)), WRAP(BODY))))); |
481 | // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
482 | // CHECK-FIXES: WRAP((void)WRAP(WRAP(LAMBDA3(WRAP([]), WRAP(()), WRAP(BODY))))); |
483 | |
484 | (void)WRAP([](void) {}); |
485 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
486 | // CHECK-FIXES: (void)WRAP([]() {}); |
487 | |
488 | [](void) BODY; |
489 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] |
490 | // CHECK-FIXES: []() BODY; |
491 | } |
492 | |
493 | namespace qqq { |
494 | void foo() BODY |
495 | void bar(void) BODY; |
496 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant void argument list in function definition |
497 | // CHECK-FIXES: void bar() BODY; |
498 | } |
499 | |
500 | struct S_1 { |
501 | void g_1(void) const { |
502 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant void argument list in function definition [modernize-redundant-void-arg] |
503 | // CHECK-FIXES: void g_1() const { |
504 | int a; |
505 | (void)a; |
506 | } |
507 | |
508 | void g_2() const { |
509 | int a; |
510 | (void)a; |
511 | } |
512 | }; |
513 | |
514 | template <typename T0> |
515 | struct S_2 { |
516 | void g_1(void) const { |
517 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant void argument list in function definition [modernize-redundant-void-arg] |
518 | // CHECK-FIXES: void g_1() const { |
519 | int a; |
520 | (void)a; |
521 | } |
522 | |
523 | void g_2() const { |
524 | int a; |
525 | (void)a; |
526 | } |
527 | }; |
528 | |
529 | template <typename T0> |
530 | struct S_3 { |
531 | template <typename T1> |
532 | void g_1(void) const { |
533 | // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant void argument list in function definition [modernize-redundant-void-arg] |
534 | // CHECK-FIXES: void g_1() const { |
535 | int a; |
536 | (void)a; |
537 | } |
538 | template <typename T2> |
539 | void g_2() const { |
540 | int a; |
541 | (void)a; |
542 | } |
543 | }; |
544 | |
545 | template <typename T1> |
546 | void g_3(void) { |
547 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant void argument list in function definition [modernize-redundant-void-arg] |
548 | // CHECK-FIXES: void g_3() { |
549 | int a; |
550 | (void)a; |
551 | } |
552 | |
553 | //Template instantiation |
554 | void f_testTemplate() { |
555 | S_1(); |
556 | S_2<int>(); |
557 | S_3<int>(); |
558 | g_3<int>(); |
559 | } |
560 | |
561 | #define return_t(T) T |
562 | extern return_t(void) func(void); |
563 | // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: redundant void argument list in function declaration |
564 | // CHECK-FIXES: extern return_t(void) func(); |
565 | |
566 | return_t(void) func(void) { |
567 | // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: redundant void argument list in function definition |
568 | // CHECK-FIXES: return_t(void) func() { |
569 | int a; |
570 | (void)a; |
571 | } |
572 | |
573 | extern return_t(void) func(return_t(void) (*fp)(void)); |
574 | // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: redundant void argument list in variable declaration |
575 | // CHECK-FIXES: extern return_t(void) func(return_t(void) (*fp)()); |
576 | |
577 | return_t(void) func(return_t(void) (*fp)(void)) { |
578 | // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: redundant void argument list in variable declaration |
579 | // CHECK-FIXES: return_t(void) func(return_t(void) (*fp)()) { |
580 | int a; |
581 | (void)a; |
582 | } |
583 | |
584 | extern return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)(void)); |
585 | // CHECK-MESSAGES: :[[@LINE-1]]:70: warning: redundant void argument list in variable declaration |
586 | // CHECK-FIXES: extern return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)()); |
587 | |
588 | return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)(void)) { |
589 | // CHECK-MESSAGES: :[[@LINE-1]]:63: warning: redundant void argument list in variable declaration |
590 | // CHECK-FIXES: return_t(return_t(void)) func2(return_t(return_t(void)) (*fp)()) { |
591 | int a; |
592 | (void)a; |
593 | } |
594 | #undef return_t |
595 | |