Skip to content

Commit 29afd5a

Browse files
authored
[clang-tidy] Fix false-positive in inconsistent-declaration-parameter-name (#170593)
Closes #169195
1 parent fda85a1 commit 29afd5a

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration,
107107

108108
while (SourceParamIt != ParameterSourceDeclaration->param_end() &&
109109
OtherParamIt != OtherDeclaration->param_end()) {
110+
if ((*SourceParamIt)->isParameterPack() !=
111+
(*OtherParamIt)->isParameterPack())
112+
break;
113+
110114
auto SourceParamName = (*SourceParamIt)->getName();
111115
auto OtherParamName = (*OtherParamIt)->getName();
112116

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ Changes in existing checks
558558
adding parentheses when the inner expression are implicitly converted
559559
multiple times.
560560

561+
- Improved :doc:`readability-inconsistent-declaration-parameter-name
562+
<clang-tidy/checks/readability/inconsistent-declaration-parameter-name>` check
563+
by not enforcing parameter name consistency between a variadic parameter pack
564+
in the primary template and specific parameters in its specializations.
565+
561566
- Improved :doc:`readability-qualified-auto
562567
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
563568
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,26 @@ struct S {
191191
void S::f(int y)
192192
{
193193
}
194+
195+
//////////////////////////////////////////////////////
196+
197+
template<typename... Args>
198+
void variadicFunctionNoWarning(Args... args);
199+
200+
template<>
201+
void variadicFunctionNoWarning(int a) {}
202+
203+
template<>
204+
void variadicFunctionNoWarning(int a, int b) {}
205+
206+
template<typename... Args>
207+
void variadicFunction2WithWarning(int fixed, Args... args);
208+
209+
template<>
210+
void variadicFunction2WithWarning(int fixed, int a) {}
211+
212+
template<>
213+
// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'variadicFunction2WithWarning<float>' has a primary template
214+
// CHECK-MESSAGES: :[[@LINE-7]]:6: note: the primary template declaration seen here
215+
// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('wrong'), in primary template declaration: ('fixed')
216+
void variadicFunction2WithWarning(int wrong, float a) {}

0 commit comments

Comments
 (0)