| 1 | // RUN: %check_clang_tidy %s readability-named-parameter %t |
| 2 | |
| 3 | void Method(char *) { /* */ } |
| 4 | // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: all parameters should be named in a function |
| 5 | // CHECK-FIXES: void Method(char * /*unused*/) { /* */ } |
| 6 | void Method2(char *) {} |
| 7 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function |
| 8 | // CHECK-FIXES: void Method2(char * /*unused*/) {} |
| 9 | void Method3(char *, void *) {} |
| 10 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function |
| 11 | // CHECK-FIXES: void Method3(char * /*unused*/, void * /*unused*/) {} |
| 12 | void Method4(char *, int /*unused*/) {} |
| 13 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function |
| 14 | // CHECK-FIXES: void Method4(char * /*unused*/, int /*unused*/) {} |
| 15 | void operator delete[](void *) throw() {} |
| 16 | // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: all parameters should be named in a function |
| 17 | // CHECK-FIXES: void operator delete[](void * /*unused*/) throw() {} |
| 18 | int Method5(int) { return 0; } |
| 19 | // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: all parameters should be named in a function |
| 20 | // CHECK-FIXES: int Method5(int /*unused*/) { return 0; } |
| 21 | void Method6(void (*)(void *)) {} |
| 22 | // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: all parameters should be named in a function |
| 23 | // CHECK-FIXES: void Method6(void (* /*unused*/)(void *)) {} |
| 24 | template <typename T> void Method7(T) {} |
| 25 | // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: all parameters should be named in a function |
| 26 | // CHECK-FIXES: template <typename T> void Method7(T /*unused*/) {} |
| 27 | |
| 28 | // Don't warn in macros. |
| 29 | #define M void MethodM(int) {} |
| 30 | M |
| 31 | |
| 32 | void operator delete(void *x) throw() {} |
| 33 | void Method7(char * /*x*/) {} |
| 34 | void Method8(char *x) {} |
| 35 | typedef void (*TypeM)(int x); |
| 36 | void operator delete[](void *x) throw(); |
| 37 | void operator delete[](void * /*x*/) throw(); |
| 38 | |
| 39 | struct X { |
| 40 | void operator++(int) {} |
| 41 | void operator--(int) {} |
| 42 | |
| 43 | X(X&) = delete; |
| 44 | X &operator=(X&) = default; |
| 45 | |
| 46 | const int &i; |
| 47 | }; |
| 48 | |
| 49 | void (*Func1)(void *); |
| 50 | void Func2(void (*func)(void *)) {} |
| 51 | template <void Func(void *)> void Func3() {} |
| 52 | |
| 53 | template <typename T> |
| 54 | struct Y { |
| 55 | void foo(T) {} |
| 56 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: all parameters should be named in a function |
| 57 | // CHECK-FIXES: void foo(T /*unused*/) {} |
| 58 | }; |
| 59 | |
| 60 | Y<int> y; |
| 61 | Y<float> z; |
| 62 | |
| 63 | struct Base { |
| 64 | virtual void foo(bool notThisOne); |
| 65 | virtual void foo(int argname); |
| 66 | }; |
| 67 | |
| 68 | struct Derived : public Base { |
| 69 | void foo(int); |
| 70 | // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: all parameters should be named in a function |
| 71 | // CHECK-FIXES: void foo(int /*argname*/); |
| 72 | }; |
| 73 | |
| 74 | void FDef(int); |
| 75 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: all parameters should be named in a function |
| 76 | // CHECK-FIXES: void FDef(int /*n*/); |
| 77 | void FDef(int n) {} |
| 78 | |
| 79 | void FDef2(int, int); |
| 80 | // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: all parameters should be named in a function |
| 81 | // CHECK-FIXES: void FDef2(int /*n*/, int /*unused*/); |
| 82 | void FDef2(int n, int) {} |
| 83 | // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: all parameters should be named in a function |
| 84 | // CHECK-FIXES: void FDef2(int n, int /*unused*/) {} |
| 85 | |
| 86 | void FNoDef(int); |
| 87 | |
| 88 | class Z {}; |
| 89 | Z the_z; |
| 90 | |
| 91 | Z &operator++(Z&) { return the_z; } |
| 92 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function |
| 93 | // CHECK-FIXES: Z &operator++(Z& /*unused*/) { return the_z; } |
| 94 | |
| 95 | Z &operator++(Z&, int) { return the_z; } |
| 96 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function |
| 97 | // CHECK-FIXES: Z &operator++(Z& /*unused*/, int) { return the_z; } |
| 98 | |
| 99 | Z &operator--(Z&) { return the_z; } |
| 100 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function |
| 101 | // CHECK-FIXES: Z &operator--(Z& /*unused*/) { return the_z; } |
| 102 | |
| 103 | Z &operator--(Z&, int) { return the_z; } |
| 104 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function |
| 105 | // CHECK-FIXES: Z &operator--(Z& /*unused*/, int) { return the_z; } |
| 106 | |
| 107 | namespace testing { |
| 108 | namespace internal { |
| 109 | class IgnoredValue { |
| 110 | public: |
| 111 | template <typename T> |
| 112 | IgnoredValue(const T& /* ignored */) {} |
| 113 | }; |
| 114 | } |
| 115 | typedef internal::IgnoredValue Unused; |
| 116 | } |
| 117 | |
| 118 | using ::testing::Unused; |
| 119 | |
| 120 | void MockFunction(Unused, int q, Unused) { |
| 121 | ++q; |
| 122 | ++q; |
| 123 | ++q; |
| 124 | } |
| 125 | |
| 126 | namespace std { |
| 127 | typedef decltype(nullptr) nullptr_t; |
| 128 | } |
| 129 | |
| 130 | void f(std::nullptr_t) {} |
| 131 | |
| 132 | typedef void (F)(int); |
| 133 | F f; |
| 134 | void f(int x) {} |
| 135 | |
| 136 | namespace issue_63056 |
| 137 | { |
| 138 | struct S { |
| 139 | S(const S&); |
| 140 | S(S&&); |
| 141 | |
| 142 | S& operator=(const S&); |
| 143 | S& operator=(S&&); |
| 144 | }; |
| 145 | |
| 146 | S::S(const S&) = default; |
| 147 | S::S(S&&) = default; |
| 148 | |
| 149 | S& S::operator=(const S&) = default; |
| 150 | S& S::operator=(S&&) = default; |
| 151 | } // namespace issue_63056 |
| 152 | |