https://github.com/xxxxbc updated 
https://github.com/llvm/llvm-project/pull/208730

>From d6f4fa2be2a953220532b2b564479117499e4310 Mon Sep 17 00:00:00 2001
From: hehuan <[email protected]>
Date: Fri, 10 Jul 2026 21:10:09 +0800
Subject: [PATCH] [clang-tidy] Ignore standard tag types in
 readability-named-parameter

The readability-named-parameter check warned on unnamed parameters whose
types are standard tag types (tag dispatch types, iterator category tags,
lock tags, etc.). These types are used exclusively for overload resolution,
so requiring a name for them only adds noise.

Add the IgnoredTypes option with a comprehensive default list of 24
standard tag types. Users can customize the list to add their own types
or remove defaults.

Fixes #208448.
---
 .../readability/NamedParameterCheck.cpp       | 44 +++++++++++++-
 .../readability/NamedParameterCheck.h         |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst       |  7 +++
 .../checks/readability/named-parameter.rst    | 38 ++++++++++++
 .../named-parameter-ignored-types.cpp         | 24 ++++++++
 .../checkers/readability/named-parameter.cpp  | 58 +++++++++++++++++++
 6 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter-ignored-types.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
index c457d682a1787..ebe8148bc4fbf 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "NamedParameterCheck.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -15,15 +16,47 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
+// Types whose parameters do not need a name (tag dispatch types, category
+// tags, etc.).
+static constexpr StringRef DefaultIgnoredTypes =
+    "std::adopt_lock_t;"
+    "std::allocator_arg_t;"
+    "std::bidirectional_iterator_tag;"
+    "std::contiguous_iterator_tag;"
+    "std::default_sentinel_t;"
+    "std::defer_lock_t;"
+    "std::destroying_delete_t;"
+    "std::forward_iterator_tag;"
+    "std::from_range_t;"
+    "std::in_place_index_t;"
+    "std::in_place_t;"
+    "std::in_place_type_t;"
+    "std::input_iterator_tag;"
+    "std::nothrow_t;"
+    "std::nostopstate_t;"
+    "std::nullopt_t;"
+    "std::output_iterator_tag;"
+    "std::piecewise_construct_t;"
+    "std::random_access_iterator_tag;"
+    "std::sorted_equivalent_t;"
+    "std::sorted_unique_t;"
+    "std::try_to_lock_t;"
+    "std::unexpect_t;"
+    "std::unreachable_sentinel_t";
+
 NamedParameterCheck::NamedParameterCheck(StringRef Name,
                                          ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
       InsertPlainNamesInForwardDecls(
-          Options.get("InsertPlainNamesInForwardDecls", false)) {}
+          Options.get("InsertPlainNamesInForwardDecls", false)),
+      IgnoredTypes(utils::options::parseStringList(
+          Options.get("IgnoredTypes", DefaultIgnoredTypes))) {}
 
 void NamedParameterCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "InsertPlainNamesInForwardDecls",
                 InsertPlainNamesInForwardDecls);
+  Options.store(Opts, "IgnoredTypes",
+                utils::options::serializeStringList(IgnoredTypes));
 }
 
 void NamedParameterCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
@@ -75,6 +108,15 @@ void NamedParameterCheck::check(const 
MatchFinder::MatchResult &Result) {
     if (Parm->getType().getCanonicalType()->isNullPtrType())
       continue;
 
+    // Skip the types configured by the IgnoredTypes option (e.g. standard
+    // tag dispatch types).
+    if (const auto *Record =
+            Parm->getType().getCanonicalType()->getAsCXXRecordDecl()) {
+      const std::string QName = Record->getQualifiedNameAsString();
+      if (llvm::is_contained(IgnoredTypes, QName))
+        continue;
+    }
+
     // Look for comments. We explicitly want to allow idioms like
     // void foo(int /*unused*/)
     const char *Begin = SM.getCharacterData(Parm->getBeginLoc());
diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h 
b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
index ecd128d887f84..9b719129fd712 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
@@ -36,6 +36,7 @@ class NamedParameterCheck : public ClangTidyCheck {
 
 private:
   const bool InsertPlainNamesInForwardDecls;
+  const std::vector<StringRef> IgnoredTypes;
 };
 
 } // namespace clang::tidy::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 082cc5cb78bc0..9080fdbe697e6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -854,6 +854,13 @@ Changes in existing checks
   <clang-tidy/checks/readability/inconsistent-ifelse-braces>` check to
   correctly handle labeled statements of ``if``/``else`` bodies.
 
+- Improved :doc:`readability-named-parameter
+  <clang-tidy/checks/readability/named-parameter>` check by ignoring
+  standard tag dispatch types (e.g. ``std::in_place_t``,
+  ``std::allocator_arg_t``, ``std::nothrow_t``) that are used exclusively for
+  overload resolution. Added the :option:`IgnoredTypes` option to allow
+  customizing the set of ignored types.
+
 - Improved :doc:`readability-non-const-parameter
   <clang-tidy/checks/readability/non-const-parameter>` check:
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
index 0dd25e23fc653..2ab19173055b1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/named-parameter.rst
@@ -25,6 +25,11 @@ function definition.
 
 Corresponding cpplint.py check name: `readability/function`.
 
+The check ignores parameters whose types are standard tag types (e.g.
+``std::in_place_t``, ``std::allocator_arg_t``, ``std::nothrow_t``,
+iterator tags, lock tags, etc.). The set of ignored types can be customized
+with the :option:`IgnoredTypes` option.
+
 Options
 -------
 
@@ -33,3 +38,36 @@ Options
    If set to `true`, the check will insert parameter names without comments for
    forward declarations only. Otherwise, the check will insert parameter names
    as comments (e.g., ``/*param*/``). Default is `false`.
+
+.. option:: IgnoredTypes
+
+   A semicolon-separated list of fully-qualified type names whose parameters
+   do not need to be named (for example, tag dispatch types, iterator tags,
+   etc.). Defaults to the standard tag types:
+
+   .. code-block:: text
+
+      std::adopt_lock_t
+      std::allocator_arg_t
+      std::bidirectional_iterator_tag
+      std::contiguous_iterator_tag
+      std::default_sentinel_t
+      std::defer_lock_t
+      std::destroying_delete_t
+      std::forward_iterator_tag
+      std::from_range_t
+      std::in_place_index_t
+      std::in_place_t
+      std::in_place_type_t
+      std::input_iterator_tag
+      std::nothrow_t
+      std::nostopstate_t
+      std::nullopt_t
+      std::output_iterator_tag
+      std::piecewise_construct_t
+      std::random_access_iterator_tag
+      std::sorted_equivalent_t
+      std::sorted_unique_t
+      std::try_to_lock_t
+      std::unexpect_t
+      std::unreachable_sentinel_t
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter-ignored-types.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter-ignored-types.cpp
new file mode 100644
index 0000000000000..9e39ef00f1161
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter-ignored-types.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-named-parameter %t -- \
+// RUN:   -config="{CheckOptions: [{key: 
readability-named-parameter.IgnoredTypes, value: 'MyCustomTag'}]}"
+
+struct MyCustomTag {};
+struct OtherTag {};
+
+// MyCustomTag is in the custom IgnoredTypes list, so it should not warn.
+void f_custom(MyCustomTag) {}
+
+// OtherTag is NOT in the custom list, so it should warn.
+void f_other(OtherTag) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: all parameters should be named in 
a function
+// CHECK-FIXES: void f_other(OtherTag /*unused*/) {}
+
+// int is not in the custom list either, so it should warn.
+void f_int(int) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: all parameters should be named in 
a function
+// CHECK-FIXES: void f_int(int /*unused*/) {}
+
+// Verify the default std types are NOT ignored when a custom list replaces 
them.
+namespace std { struct in_place_t {}; }
+void f_in_place(std::in_place_t) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: all parameters should be named in 
a function
+// CHECK-FIXES: void f_in_place(std::in_place_t /*unused*/) {}
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp
index 8ae0d7055867b..6b82b8e6be96f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp
@@ -161,10 +161,68 @@ void MockFunction(Unused, int q, Unused) {
 
 namespace std {
 typedef decltype(nullptr) nullptr_t;
+struct adopt_lock_t {};
+struct allocator_arg_t {};
+struct bidirectional_iterator_tag {};
+struct contiguous_iterator_tag {};
+struct default_sentinel_t {};
+struct defer_lock_t {};
+struct forward_iterator_tag {};
+struct from_range_t {};
+template<unsigned I> struct in_place_index_t {};
+struct in_place_t {};
+template<class T> struct in_place_type_t {};
+struct input_iterator_tag {};
+struct nothrow_t {};
+struct nostopstate_t {};
+struct nullopt_t {};
+struct output_iterator_tag {};
+struct piecewise_construct_t {};
+struct random_access_iterator_tag {};
+struct sorted_equivalent_t {};
+struct sorted_unique_t {};
+struct try_to_lock_t {};
+struct unexpect_t {};
+struct unreachable_sentinel_t {};
+struct destroying_delete_t {};
 }
 
 void f(std::nullptr_t) {}
 
+// Standard tag dispatch types should not trigger warnings.
+void f_adopt_lock(std::adopt_lock_t) {}
+void f_allocator_arg(std::allocator_arg_t) {}
+void f_bidir_iter(std::bidirectional_iterator_tag) {}
+void f_contig_iter(std::contiguous_iterator_tag) {}
+void f_default_sentinel(std::default_sentinel_t) {}
+void f_defer_lock(std::defer_lock_t) {}
+void f_destroying(std::destroying_delete_t) {}
+void f_forward_iter(std::forward_iterator_tag) {}
+void f_from_range(std::from_range_t) {}
+void f_in_place_index(std::in_place_index_t<0>) {}
+void f_in_place(std::in_place_t) {}
+void f_in_place_type(std::in_place_type_t<int>) {}
+void f_input_iter(std::input_iterator_tag) {}
+void f_nothrow(std::nothrow_t) {}
+void f_nostopstate(std::nostopstate_t) {}
+void f_nullopt(std::nullopt_t) {}
+void f_output_iter(std::output_iterator_tag) {}
+void f_piecewise(std::piecewise_construct_t) {}
+void f_random_iter(std::random_access_iterator_tag) {}
+void f_sorted_equivalent(std::sorted_equivalent_t) {}
+void f_sorted_unique(std::sorted_unique_t) {}
+void f_try_to_lock(std::try_to_lock_t) {}
+void f_unexpect(std::unexpect_t) {}
+void f_unreachable_sentinel(std::unreachable_sentinel_t) {}
+
+// A type not in the IgnoredTypes list should still trigger a warning.
+struct NotATag {};
+void f_not_a_tag(NotATag) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: all parameters should be named in 
a function
+// CHECK-FIXES: void f_not_a_tag(NotATag /*unused*/) {}
+// CHECK-MESSAGES-PLAIN-NAMES: :[[@LINE-3]]:25: warning: all parameters should 
be named in a function
+// CHECK-FIXES-PLAIN-NAMES: void f_not_a_tag(NotATag /*unused*/) {}
+
 typedef void (F)(int);
 F f;
 void f(int x) {}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to