1// RUN: %check_clang_tidy %s readability-named-parameter %t
2
3void Method(char *) { /* */ }
4// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: all parameters should be named in a function
5// CHECK-FIXES: void Method(char * /*unused*/) { /* */ }
6void Method2(char *) {}
7// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: all parameters should be named in a function
8// CHECK-FIXES: void Method2(char * /*unused*/) {}
9void 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*/) {}
12void 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*/) {}
15void 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() {}
18int 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; }
21void 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 *)) {}
24template <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) {}
30M
31
32void operator delete(void *x) throw() {}
33void Method7(char * /*x*/) {}
34void Method8(char *x) {}
35typedef void (*TypeM)(int x);
36void operator delete[](void *x) throw();
37void operator delete[](void * /*x*/) throw();
38
39struct X {
40 X operator++(int) {}
41 X operator--(int) {}
42
43 X(X&) = delete;
44 X &operator=(X&) = default;
45
46 const int &i;
47};
48
49void (*Func1)(void *);
50void Func2(void (*func)(void *)) {}
51template <void Func(void *)> void Func3() {}
52
53template <typename T>
54struct 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
60Y<int> y;
61Y<float> z;
62
63struct Base {
64 virtual void foo(bool notThisOne);
65 virtual void foo(int argname);
66};
67
68struct 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
74void FDef(int);
75// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: all parameters should be named in a function
76// CHECK-FIXES: void FDef(int /*n*/);
77void FDef(int n) {}
78
79void 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*/);
82void 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
86void FNoDef(int);
87
88class Z {};
89
90Z &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
94Z &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
98Z &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
102Z &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
106namespace testing {
107namespace internal {
108class IgnoredValue {
109 public:
110 template <typename T>
111 IgnoredValue(const T& /* ignored */) {}
112};
113}
114typedef internal::IgnoredValue Unused;
115}
116
117using ::testing::Unused;
118
119void MockFunction(Unused, int q, Unused) {
120 ++q;
121 ++q;
122 ++q;
123}
124
125namespace std {
126typedef decltype(nullptr) nullptr_t;
127}
128
129void f(std::nullptr_t) {}
130
131typedef void (F)(int);
132F f;
133void f(int x) {}
134
135namespace issue_63056
136{
137 struct S {
138 S(const S&);
139 S(S&&);
140
141 S& operator=(const S&);
142 S& operator=(S&&);
143 };
144
145 S::S(const S&) = default;
146 S::S(S&&) = default;
147
148 S& S::operator=(const S&) = default;
149 S& S::operator=(S&&) = default;
150} // namespace issue_63056
151

source code of clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp