1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// RUN: %check_clang_tidy %s readability-avoid-const-params-in-decls %t
using alias_type = bool;
using alias_const_type = const bool;
void F1(const int i);
// 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]
// CHECK-FIXES: void F1(int i);
void F2(const int *const i);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
// CHECK-FIXES: void F2(const int *i);
void F3(int const i);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
// CHECK-FIXES: void F3(int i);
void F4(alias_type const i);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
// CHECK-FIXES: void F4(alias_type i);
void F5(const int);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified
// CHECK-FIXES: void F5(int);
void F6(const int *const);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified
// CHECK-FIXES: void F6(const int *);
void F7(int, const int);
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: parameter 2 is const-qualified
// CHECK-FIXES: void F7(int, int);
void F8(const int, const int);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 1 is const-qualified
// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: parameter 2 is const-qualified
// CHECK-FIXES: void F8(int, int);
void F9(const int long_name);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'long_name'
// CHECK-FIXES: void F9(int long_name);
void F10(const int *const *const long_name);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'long_name'
// CHECK-FIXES: void F10(const int *const *long_name);
void F11(const unsigned int /*v*/);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 1
// CHECK-FIXES: void F11(unsigned int /*v*/);
void F12(const bool b = true);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
// CHECK-FIXES: void F12(bool b = true);
template<class T>
int F13(const bool b = true);
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
// CHECK-FIXES: int F13(bool b = true);
int f13 = F13<int>();
struct Foo {
Foo(const int i);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
// CHECK-FIXES: Foo(int i);
void operator()(const int i);
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
// CHECK-FIXES: void operator()(int i);
};
template <class T>
struct FooT {
FooT(const int i);
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
// CHECK-FIXES: FooT(int i);
void operator()(const int i);
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
// CHECK-FIXES: void operator()(int i);
};
FooT<int> f(1);
// Do not match on definitions
void NF1(const int i) {}
void NF2(const int *const i) {}
void NF3(int const i) {}
void NF4(alias_type const i) {}
void NF5(const int) {}
void NF6(const int *const) {}
void NF7(int, const int) {}
void NF8(const int, const int) {}
template <class T>
int NF9(const int, const int) { return 0; }
int nf9 = NF9<int>(1, 2);
// Do not match on inline member functions
struct Bar {
Bar(const int i) {}
void operator()(const int i) {}
};
// Do not match on inline member functions of a templated class
template <class T>
struct BarT {
BarT(const int i) {}
void operator()(const int i) {}
};
BarT<int> b(1);
// Do not match on other stuff
void NF(const alias_type& i);
void NF(const int &i);
void NF(const int *i);
void NF(alias_const_type i);
void NF(const alias_type&);
void NF(const int&);
void NF(const int*);
void NF(const int* const*);
void NF(alias_const_type);
// Regression test for when the 'const' token is not in the code.
#define CONCAT(a, b) a##b
void ConstNotVisible(CONCAT(cons, t) int i);
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: parameter 'i'
// We warn, but we can't give a fix
// CHECK-FIXES: void ConstNotVisible(CONCAT(cons, t) int i);
// Regression test. We should not warn (or crash) on lambda expressions
auto lambda_with_name = [](const int n) {};
auto lambda_without_name = [](const int) {};
|