1// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- --fix-notes -- -fno-delayed-template-parsing
2
3void consistentFunction(int a, int b, int c);
4void consistentFunction(int a, int b, int c);
5void consistentFunction(int prefixA, int b, int cSuffix);
6void consistentFunction(int a, int b, int c);
7void consistentFunction(int a, int b, int /*c*/);
8void consistentFunction(int /*c*/, int /*c*/, int /*c*/);
9
10//////////////////////////////////////////////////////
11
12// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: function 'inconsistentFunction' has 2 other declarations with different parameter names [readability-inconsistent-declaration-parameter-name]
13void inconsistentFunction(int a, int b, int c);
14// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 1st inconsistent declaration seen here
15// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('d', 'e', 'f'), in the other declaration: ('a', 'b', 'c')
16void inconsistentFunction(int d, int e, int f);
17// CHECK-MESSAGES: :[[@LINE+2]]:6: note: the 2nd inconsistent declaration seen here
18// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('x', 'y', 'z'), in the other declaration: ('a', 'b', 'c')
19void inconsistentFunction(int x, int y, int z);
20
21//////////////////////////////////////////////////////
22
23// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]
24// CHECK-MESSAGES: :[[@LINE+9]]:6: note: the definition seen here
25// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('a'), in definition: ('c')
26// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c);
27void inconsistentFunctionWithVisibleDefinition(int a);
28// CHECK-MESSAGES: :[[@LINE+4]]:6: warning: function 'inconsistentFunctionWithVisibleDefinition' has a definition
29// CHECK-MESSAGES: :[[@LINE+4]]:6: note: the definition seen here
30// CHECK-MESSAGES: :[[@LINE+2]]:6: note: differing parameters are named here: ('b'), in definition: ('c')
31// CHECK-FIXES: void inconsistentFunctionWithVisibleDefinition(int c);
32void inconsistentFunctionWithVisibleDefinition(int b);
33void inconsistentFunctionWithVisibleDefinition(int c) { c; }
34
35// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function 'inconsidentFunctionWithUnreferencedParameterInDefinition' has a definition
36// CHECK-MESSAGES: :[[@LINE+3]]:6: note: the definition seen here
37// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('a'), in definition: ('b')
38void inconsidentFunctionWithUnreferencedParameterInDefinition(int a);
39void inconsidentFunctionWithUnreferencedParameterInDefinition(int b) {}
40
41//////////////////////////////////////////////////////
42
43struct Struct {
44// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Struct::inconsistentFunction' has a definition
45// CHECK-MESSAGES: :[[@LINE+6]]:14: note: the definition seen here
46// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b')
47// CHECK-FIXES: void inconsistentFunction(int b);
48 void inconsistentFunction(int a);
49};
50
51void Struct::inconsistentFunction(int b) { b = 0; }
52
53//////////////////////////////////////////////////////
54
55struct SpecialFunctions {
56// CHECK-MESSAGES: :[[@LINE+4]]:3: warning: function 'SpecialFunctions::SpecialFunctions' has a definition
57// CHECK-MESSAGES: :[[@LINE+12]]:19: note: the definition seen here
58// CHECK-MESSAGES: :[[@LINE+2]]:3: note: differing parameters are named here: ('a'), in definition: ('b')
59// CHECK-FIXES: SpecialFunctions(int b);
60 SpecialFunctions(int a);
61
62// CHECK-MESSAGES: :[[@LINE+4]]:21: warning: function 'SpecialFunctions::operator=' has a definition
63// CHECK-MESSAGES: :[[@LINE+8]]:37: note: the definition seen here
64// CHECK-MESSAGES: :[[@LINE+2]]:21: note: differing parameters are named here: ('a'), in definition: ('b')
65// CHECK-FIXES: SpecialFunctions& operator=(const SpecialFunctions& b);
66 SpecialFunctions& operator=(const SpecialFunctions& a);
67};
68
69SpecialFunctions::SpecialFunctions(int b) { b; }
70
71SpecialFunctions& SpecialFunctions::operator=(const SpecialFunctions& b) { b; return *this; }
72
73//////////////////////////////////////////////////////
74
75// CHECK-MESSAGES: :[[@LINE+5]]:6: warning: function 'templateFunctionWithSeparateDeclarationAndDefinition' has a definition
76// CHECK-MESSAGES: :[[@LINE+7]]:6: note: the definition seen here
77// CHECK-MESSAGES: :[[@LINE+3]]:6: note: differing parameters are named here: ('a'), in definition: ('b')
78// CHECK-FIXES: void templateFunctionWithSeparateDeclarationAndDefinition(T b);
79template<typename T>
80void templateFunctionWithSeparateDeclarationAndDefinition(T a);
81
82template<typename T>
83void templateFunctionWithSeparateDeclarationAndDefinition(T b) { b; }
84
85//////////////////////////////////////////////////////
86
87template<typename T>
88void templateFunctionWithSpecializations(T a) { a; }
89
90template<>
91// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSpecializations<int>' has a primary template declaration with different parameter names [readability-inconsistent-declaration-parameter-name]
92// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here
93// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
94void templateFunctionWithSpecializations(int b) { b; }
95
96template<>
97// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSpecializations<float>' has a primary template
98// CHECK-MESSAGES: :[[@LINE-10]]:6: note: the primary template declaration seen here
99// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('c'), in primary template declaration: ('a')
100void templateFunctionWithSpecializations(float c) { c; }
101
102//////////////////////////////////////////////////////
103
104template<typename T>
105void templateFunctionWithoutDefinitionButWithSpecialization(T a);
106
107template<>
108// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithoutDefinitionButWithSpecialization<int>' has a primary template
109// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here
110// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
111void templateFunctionWithoutDefinitionButWithSpecialization(int b) { b; }
112
113//////////////////////////////////////////////////////
114
115template<typename T>
116void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(T a);
117
118template<>
119// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSeparateSpecializationDeclarationAndDefinition<int>' has a primary template
120// CHECK-MESSAGES: :[[@LINE-4]]:6: note: the primary template declaration seen here
121// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
122void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int b);
123
124template<>
125// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'templateFunctionWithSeparateSpecializationDeclarationAndDefinition<int>' has a primary template
126// CHECK-MESSAGES: :[[@LINE-10]]:6: note: the primary template declaration seen here
127// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('c'), in primary template declaration: ('a')
128void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int c) { c; }
129
130//////////////////////////////////////////////////////
131
132template<typename T>
133class ClassTemplate
134{
135public:
136// CHECK-MESSAGES: :[[@LINE+4]]:10: warning: function 'ClassTemplate::functionInClassTemplateWithSeparateDeclarationAndDefinition' has a definition
137// CHECK-MESSAGES: :[[@LINE+7]]:24: note: the definition seen here
138// CHECK-MESSAGES: :[[@LINE+2]]:10: note: differing parameters are named here: ('a'), in definition: ('b')
139// CHECK-FIXES: void functionInClassTemplateWithSeparateDeclarationAndDefinition(int b);
140 void functionInClassTemplateWithSeparateDeclarationAndDefinition(int a);
141};
142
143template<typename T>
144void ClassTemplate<T>::functionInClassTemplateWithSeparateDeclarationAndDefinition(int b) { b; }
145
146//////////////////////////////////////////////////////
147
148class Class
149{
150public:
151 template<typename T>
152// CHECK-MESSAGES: :[[@LINE+4]]:8: warning: function 'Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition' has a definition
153// CHECK-MESSAGES: :[[@LINE+12]]:13: note: the definition seen here
154// CHECK-MESSAGES: :[[@LINE+2]]:8: note: differing parameters are named here: ('a'), in definition: ('b')
155// CHECK-FIXES: void memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b);
156 void memberFunctionTemplateWithSeparateDeclarationAndDefinition(T a);
157
158 template<typename T>
159 void memberFunctionTemplateWithSpecializations(T a) { a; }
160};
161
162//////////////////////////////////////////////////////
163
164template<typename T>
165void Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b) { b; }
166
167//////////////////////////////////////////////////////
168
169template<>
170// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: function template specialization 'Class::memberFunctionTemplateWithSpecializations<int>' has a primary template
171// CHECK-MESSAGES: :[[@LINE-12]]:8: note: the primary template declaration seen here
172// CHECK-MESSAGES: :[[@LINE+1]]:13: note: differing parameters are named here: ('b'), in primary template declaration: ('a')
173void Class::memberFunctionTemplateWithSpecializations(int b) { b; }
174
175template<>
176// CHECK-MESSAGES: :[[@LINE+3]]:13: warning: function template specialization 'Class::memberFunctionTemplateWithSpecializations<float>' has a primary template
177// CHECK-MESSAGES: :[[@LINE-18]]:8: note: the primary template declaration seen here
178// CHECK-MESSAGES: :[[@LINE+1]]:13: note: differing parameters are named here: ('c'), in primary template declaration: ('a')
179void Class::memberFunctionTemplateWithSpecializations(float c) { c; }
180
181//////////////////////////////////////////////////////
182
183// This resulted in a warning by default.
184#define MACRO() \
185 void f(int x);
186
187struct S {
188 MACRO();
189};
190
191void S::f(int y)
192{
193}
194

source code of clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp