1 | // RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- --fix-notes -- -fno-delayed-template-parsing |
2 | |
3 | void consistentFunction(int a, int b, int c); |
4 | void consistentFunction(int a, int b, int c); |
5 | void consistentFunction(int prefixA, int b, int cSuffix); |
6 | void consistentFunction(int a, int b, int c); |
7 | void consistentFunction(int a, int b, int /*c*/); |
8 | void 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] |
13 | void 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') |
16 | void 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') |
19 | void 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); |
27 | void 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); |
32 | void inconsistentFunctionWithVisibleDefinition(int b); |
33 | void 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') |
38 | void inconsidentFunctionWithUnreferencedParameterInDefinition(int a); |
39 | void inconsidentFunctionWithUnreferencedParameterInDefinition(int b) {} |
40 | |
41 | ////////////////////////////////////////////////////// |
42 | |
43 | struct 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 | |
51 | void Struct::inconsistentFunction(int b) { b = 0; } |
52 | |
53 | ////////////////////////////////////////////////////// |
54 | |
55 | struct 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 | |
69 | SpecialFunctions::SpecialFunctions(int b) { b; } |
70 | |
71 | SpecialFunctions& 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); |
79 | template<typename T> |
80 | void templateFunctionWithSeparateDeclarationAndDefinition(T a); |
81 | |
82 | template<typename T> |
83 | void templateFunctionWithSeparateDeclarationAndDefinition(T b) { b; } |
84 | |
85 | ////////////////////////////////////////////////////// |
86 | |
87 | template<typename T> |
88 | void templateFunctionWithSpecializations(T a) { a; } |
89 | |
90 | template<> |
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') |
94 | void templateFunctionWithSpecializations(int b) { b; } |
95 | |
96 | template<> |
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') |
100 | void templateFunctionWithSpecializations(float c) { c; } |
101 | |
102 | ////////////////////////////////////////////////////// |
103 | |
104 | template<typename T> |
105 | void templateFunctionWithoutDefinitionButWithSpecialization(T a); |
106 | |
107 | template<> |
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') |
111 | void templateFunctionWithoutDefinitionButWithSpecialization(int b) { b; } |
112 | |
113 | ////////////////////////////////////////////////////// |
114 | |
115 | template<typename T> |
116 | void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(T a); |
117 | |
118 | template<> |
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') |
122 | void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int b); |
123 | |
124 | template<> |
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') |
128 | void templateFunctionWithSeparateSpecializationDeclarationAndDefinition(int c) { c; } |
129 | |
130 | ////////////////////////////////////////////////////// |
131 | |
132 | template<typename T> |
133 | class ClassTemplate |
134 | { |
135 | public: |
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 | |
143 | template<typename T> |
144 | void ClassTemplate<T>::functionInClassTemplateWithSeparateDeclarationAndDefinition(int b) { b; } |
145 | |
146 | ////////////////////////////////////////////////////// |
147 | |
148 | class Class |
149 | { |
150 | public: |
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 | |
164 | template<typename T> |
165 | void Class::memberFunctionTemplateWithSeparateDeclarationAndDefinition(T b) { b; } |
166 | |
167 | ////////////////////////////////////////////////////// |
168 | |
169 | template<> |
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') |
173 | void Class::memberFunctionTemplateWithSpecializations(int b) { b; } |
174 | |
175 | template<> |
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') |
179 | void 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 | |
187 | struct S { |
188 | MACRO(); |
189 | }; |
190 | |
191 | void S::f(int y) |
192 | { |
193 | } |
194 | |