[clang-tools-extra] [clang-tidy] Ignore non-forwarded arguments if they are unnamed (PR #87832)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 5 14:43:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clang-tidy
Author: Danny Mösch (SimplyDanny)
<details>
<summary>Changes</summary>
Fixes #<!-- -->87697.
---
Full diff: https://github.com/llvm/llvm-project/pull/87832.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp (+9-6)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4)
- (modified) clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp (+3)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 87fd8adf997082..6817bcb24c8112 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -79,6 +79,8 @@ AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
return Node.getCaptureDefault() == Kind;
}
+AST_MATCHER(ParmVarDecl, hasAnyName) { return !Node.getName().empty(); }
+
} // namespace
void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
@@ -125,12 +127,13 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
hasAncestor(expr(hasUnevaluatedContext())))));
Finder->addMatcher(
- parmVarDecl(parmVarDecl().bind("param"), isTemplateTypeParameter(),
- hasAncestor(functionDecl().bind("func")),
- hasAncestor(functionDecl(
- isDefinition(), equalsBoundNode("func"), ToParam,
- unless(anyOf(isDeleted(), hasDescendant(std::move(
- ForwardCallMatcher))))))),
+ parmVarDecl(
+ parmVarDecl().bind("param"), hasAnyName(), isTemplateTypeParameter(),
+ hasAncestor(functionDecl().bind("func")),
+ hasAncestor(functionDecl(
+ isDefinition(), equalsBoundNode("func"), ToParam,
+ unless(anyOf(isDeleted(),
+ hasDescendant(std::move(ForwardCallMatcher))))))),
this);
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 456e09204fa2f9..f79d3b9f362063 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -182,6 +182,10 @@ Changes in existing checks
giving false positives for deleted functions and fix false negative when some
parameters are forwarded, but other aren't.
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+ <clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by ignoring
+ parameters without a name (unused arguments).
+
- Improved :doc:`cppcoreguidelines-owning-memory
<clang-tidy/checks/cppcoreguidelines/owning-memory>` check to properly handle
return type in lambdas and in nested functions.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index 9a50eabf619bd5..c435a0e023ba0b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
@@ -198,3 +198,6 @@ struct S {
};
} // namespace deleted_functions
+
+template<typename F>
+void unused_argument(F&&) {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/87832
More information about the cfe-commits
mailing list