https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/170593
>From 496ffc1cc16e62bc0c61080209e7f28b91efd74d Mon Sep 17 00:00:00 2001 From: mtx <[email protected]> Date: Tue, 2 Dec 2025 14:50:56 +0800 Subject: [PATCH 1/3] [clang-tidy] Fix false-positive in inconsistent-declaration-parameter-name --- ...onsistentDeclarationParameterNameCheck.cpp | 4 +++ clang-tools-extra/docs/ReleaseNotes.rst | 5 ++++ ...nconsistent-declaration-parameter-name.cpp | 29 +++++++++++++++++++ 3 files changed, 38 insertions(+) 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 79a768e599cfd..d91bc99b2ef44 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -545,6 +545,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..9e390d89303ba 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,32 @@ struct S { void S::f(int y) { } + +////////////////////////////////////////////////////// + +template<typename... Args> +void variadicFunctionNoWarning(Args... args); + +template<> +// CHECK-NOT: warning: function template specialization 'variadicFunctionNoWarning<int>' +// CHECK-NOT: readability-inconsistent-declaration-parameter-name +void variadicFunctionNoWarning(int a) {} + +template<> +// CHECK-NOT: warning: function template specialization 'variadicFunctionNoWarning<int, int>' +// CHECK-NOT: readability-inconsistent-declaration-parameter-name +void variadicFunctionNoWarning(int a, int b) {} + +template<typename... Args> +void variadicFunction2WithWarning(int fixed, Args... args); + +template<> +// CHECK-NOT: warning: function template specialization 'variadicFunction2WithWarning<int>' +// CHECK-NOT: readability-inconsistent-declaration-parameter-name +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-9]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('wrong'), in primary template declaration: ('fixed') +void variadicFunction2WithWarning(int wrong, float a) {} >From 2b65b9381c82a4a7c7af253a2f418f21aec2a190 Mon Sep 17 00:00:00 2001 From: mtx <[email protected]> Date: Thu, 4 Dec 2025 16:13:04 +0800 Subject: [PATCH 2/3] ~ --- .../readability/inconsistent-declaration-parameter-name.cpp | 6 ------ 1 file changed, 6 deletions(-) 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 9e390d89303ba..242c47581daf5 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 @@ -198,21 +198,15 @@ template<typename... Args> void variadicFunctionNoWarning(Args... args); template<> -// CHECK-NOT: warning: function template specialization 'variadicFunctionNoWarning<int>' -// CHECK-NOT: readability-inconsistent-declaration-parameter-name void variadicFunctionNoWarning(int a) {} template<> -// CHECK-NOT: warning: function template specialization 'variadicFunctionNoWarning<int, int>' -// CHECK-NOT: readability-inconsistent-declaration-parameter-name void variadicFunctionNoWarning(int a, int b) {} template<typename... Args> void variadicFunction2WithWarning(int fixed, Args... args); template<> -// CHECK-NOT: warning: function template specialization 'variadicFunction2WithWarning<int>' -// CHECK-NOT: readability-inconsistent-declaration-parameter-name void variadicFunction2WithWarning(int fixed, int a) {} template<> >From 75d56c8bcf14337d289b88fd7de3c4179b935526 Mon Sep 17 00:00:00 2001 From: mtx <[email protected]> Date: Thu, 4 Dec 2025 16:27:43 +0800 Subject: [PATCH 3/3] Fix line number offset --- .../readability/inconsistent-declaration-parameter-name.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 242c47581daf5..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 @@ -211,6 +211,6 @@ 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-9]]:6: note: the primary template declaration seen here +// CHECK-MESSAGES: :[[@LINE-7]]:6: note: the primary template declaration seen here // CHECK-MESSAGES: :[[@LINE+1]]:6: note: differing parameters are named here: ('wrong'), in primary template declaration: ('fixed') void variadicFunction2WithWarning(int wrong, float a) {} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
