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 void operator++(int) {}
41 void 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 {};
89Z the_z;
90
91Z &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
95Z &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
99Z &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
103Z &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
107namespace testing {
108namespace internal {
109class IgnoredValue {
110 public:
111 template <typename T>
112 IgnoredValue(const T& /* ignored */) {}
113};
114}
115typedef internal::IgnoredValue Unused;
116}
117
118using ::testing::Unused;
119
120void MockFunction(Unused, int q, Unused) {
121 ++q;
122 ++q;
123 ++q;
124}
125
126namespace std {
127typedef decltype(nullptr) nullptr_t;
128}
129
130void f(std::nullptr_t) {}
131
132typedef void (F)(int);
133F f;
134void f(int x) {}
135
136namespace 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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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