|
| 1 | +// RUN: %check_clang_tidy %s readability-avoid-const-params-in-decls %t |
| 2 | + |
| 3 | +using alias_type = bool; |
| 4 | +using alias_const_type = const bool; |
| 5 | + |
| 6 | + |
| 7 | +void F1(const int i); |
| 8 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls] |
| 9 | +// CHECK-FIXES: void F1(int i); |
| 10 | + |
| 11 | +void F2(const int *const i); |
| 12 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified |
| 13 | +// CHECK-FIXES: void F2(const int * i); |
| 14 | + |
| 15 | +void F3(int const i); |
| 16 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified |
| 17 | +// CHECK-FIXES: void F3(int i); |
| 18 | + |
| 19 | +void F4(alias_type const i); |
| 20 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified |
| 21 | +// CHECK-FIXES: void F4(alias_type i); |
| 22 | + |
| 23 | +void F5(const int); |
| 24 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified |
| 25 | +// CHECK-FIXES: void F5(int); |
| 26 | + |
| 27 | +void F6(const int *const); |
| 28 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified |
| 29 | +// BUG(b/27584482): void F6(const int *); should be produced |
| 30 | + |
| 31 | +void F7(int, const int); |
| 32 | +// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: parameter 2 is const-qualified |
| 33 | +// CHECK-FIXES: void F7(int, int); |
| 34 | + |
| 35 | +void F8(const int, const int); |
| 36 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified |
| 37 | +// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: parameter 2 is const-qualified |
| 38 | +// CHECK-FIXES: void F8(int, int); |
| 39 | + |
| 40 | +void F9(const int long_name); |
| 41 | +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'long_name' |
| 42 | +// CHECK-FIXES: void F9(int long_name); |
| 43 | + |
| 44 | +void F10(const int *const *const long_name); |
| 45 | +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'long_name' |
| 46 | +// CHECK-FIXES: void F10(const int *const * long_name); |
| 47 | + |
| 48 | + |
| 49 | +struct Foo { |
| 50 | + Foo(const int i); |
| 51 | + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i' |
| 52 | + // CHECK-FIXES: Foo(int i); |
| 53 | + |
| 54 | + void operator()(const int i); |
| 55 | + // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' |
| 56 | + // CHECK-FIXES: void operator()(int i); |
| 57 | +}; |
| 58 | + |
| 59 | +// Do not match on definitions |
| 60 | +void NF1(const int i) {} |
| 61 | +void NF2(const int *const i) {} |
| 62 | +void NF3(int const i) {} |
| 63 | +void NF4(alias_type const i) {} |
| 64 | +void NF5(const int) {} |
| 65 | +void NF6(const int *const) {} |
| 66 | +void NF7(int, const int) {} |
| 67 | +void NF8(const int, const int) {} |
| 68 | + |
| 69 | +// Do not match on other stuff |
| 70 | +void NF(const alias_type& i); |
| 71 | +void NF(const int &i); |
| 72 | +void NF(const int *i); |
| 73 | +void NF(alias_const_type i); |
| 74 | +void NF(const alias_type&); |
| 75 | +void NF(const int&); |
| 76 | +void NF(const int*); |
| 77 | +void NF(const int* const*); |
| 78 | +void NF(alias_const_type); |
0 commit comments