[clang-tools-extra] 29afd5a - [clang-tidy] Fix false-positive in inconsistent-declaration-parameter-name (#170593)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 4 01:43:23 PST 2025
Author: mitchell
Date: 2025-12-04T17:43:19+08:00
New Revision: 29afd5a9ffd33f52c5061ae2070f4b6f23f2971f
URL: https://github.com/llvm/llvm-project/commit/29afd5a9ffd33f52c5061ae2070f4b6f23f2971f
DIFF: https://github.com/llvm/llvm-project/commit/29afd5a9ffd33f52c5061ae2070f4b6f23f2971f.diff
LOG: [clang-tidy] Fix false-positive in inconsistent-declaration-parameter-name (#170593)
Closes #169195
Added:
Modified:
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
index c49684112a5d4..7b27ab92923aa 100644
--- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -107,6 +107,10 @@ findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration,
while (SourceParamIt != ParameterSourceDeclaration->param_end() &&
OtherParamIt != OtherDeclaration->param_end()) {
+ if ((*SourceParamIt)->isParameterPack() !=
+ (*OtherParamIt)->isParameterPack())
+ break;
+
auto SourceParamName = (*SourceParamIt)->getName();
auto OtherParamName = (*OtherParamIt)->getName();
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 9533d56c219f7..225ddaeedc10d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -558,6 +558,11 @@ Changes in existing checks
adding parentheses when the inner expression are implicitly converted
multiple times.
+- Improved :doc:`readability-inconsistent-declaration-parameter-name
+ <clang-tidy/checks/readability/inconsistent-declaration-parameter-name>` check
+ by not enforcing parameter name consistency between a variadic parameter pack
+ in the primary template and specific parameters in its specializations.
+
- Improved :doc:`readability-qualified-auto
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
index 982243255dd01..119a3c8589a0f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/inconsistent-declaration-parameter-name.cpp
@@ -191,3 +191,26 @@ struct S {
void S::f(int y)
{
}
+
+//////////////////////////////////////////////////////
+
+template<typename... Args>
+void variadicFunctionNoWarning(Args... args);
+
+template<>
+void variadicFunctionNoWarning(int a) {}
+
+template<>
+void variadicFunctionNoWarning(int a, int b) {}
+
+template<typename... Args>
+void variadicFunction2WithWarning(int fixed, Args... args);
+
+template<>
+void variadicFunction2WithWarning(int fixed, int a) {}
+
+template<>
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: function template specialization 'variadicFunction2WithWarning<float>' has a primary template
+// CHECK-MESSAGES: :[[@LINE-7]]:6: note: the primary template declaration seen here
+// CHECK-MESSAGES: :[[@LINE+1]]:6: note:
diff ering parameters are named here: ('wrong'), in primary template declaration: ('fixed')
+void variadicFunction2WithWarning(int wrong, float a) {}
More information about the cfe-commits
mailing list