1 // RUN: %check_clang_tidy %s readability-named-parameter %t
2 
Method(char *)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*/) { /* */ }
Method2(char *)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*/) {}
Method3(char *,void *)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*/) {}
Method4(char *,int)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*/) {}
operator delete[](void *)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() {}
Method5(int)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; }
Method6(void (*)(void *))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 *)) {}
Method7(T)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 
operator delete(void * x)32 void operator delete(void *x) throw() {}
Method7(char *)33 void Method7(char * /*x*/) {}
Method8(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 {
operator ++X40   X operator++(int) {}
operator --X41   X operator--(int) {}
42 
43   X(X&) = delete;
44   X &operator=(X&) = default;
45 
46   const int &i;
47 };
48 
49 void (*Func1)(void *);
Func2(void (* func)(void *))50 void Func2(void (*func)(void *)) {}
Func3()51 template <void Func(void *)> void Func3() {}
52 
53 template <typename T>
54 struct Y {
fooY55   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*/);
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*/);
FDef2(int n,int)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 
operator ++(Z &)90 Z &operator++(Z&) {}
91 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
92 // CHECK-FIXES: Z &operator++(Z& /*unused*/) {}
93 
operator ++(Z &,int)94 Z &operator++(Z&, int) {}
95 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
96 // CHECK-FIXES: Z &operator++(Z& /*unused*/, int) {}
97 
operator --(Z &)98 Z &operator--(Z&) {}
99 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
100 // CHECK-FIXES: Z &operator--(Z& /*unused*/) {}
101 
operator --(Z &,int)102 Z &operator--(Z&, int) {}
103 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: all parameters should be named in a function
104 // CHECK-FIXES: Z &operator--(Z& /*unused*/, int) {}
105 
106 namespace testing {
107 namespace internal {
108 class IgnoredValue {
109  public:
110   template <typename T>
IgnoredValue(const T &)111   IgnoredValue(const T& /* ignored */) {}
112 };
113 }
114 typedef internal::IgnoredValue Unused;
115 }
116 
117 using ::testing::Unused;
118 
MockFunction(Unused,int q,Unused)119 void MockFunction(Unused, int q, Unused) {
120   ++q;
121   ++q;
122   ++q;
123 }
124 
125 namespace std {
126 typedef decltype(nullptr) nullptr_t;
127 }
128 
f(std::nullptr_t)129 void f(std::nullptr_t) {}
130 
131 typedef void (F)(int);
132 F f;
f(int x)133 void f(int x) {}
134