[clang-tools-extra] [clang-tidy] Fix `performance-unnecessary-value-param` FN when passing `std::function` rvalue into `std::map::try_emplace` (PR #180806)

via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 14 02:20:58 PST 2026


================
@@ -415,4 +416,31 @@ bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
   return !Matches.empty();
 }
 
+bool isPerfectlyForwardedArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
+                                  ASTContext &Context) {
+  auto UsedAsArg = forEachArgumentWithParam(
+      ignoringParenImpCasts(declRefExpr(equalsNode(&DeclRef))),
+      parmVarDecl().bind("param"));
+  auto Matches =
+      match(decl(hasDescendant(invocation(UsedAsArg).bind("invocationExpr"))),
+            Decl, Context);
+  return std::any_of(Matches.begin(), Matches.end(), [](const auto &M) {
+    if (const auto *P = M.template getNodeAs<ParmVarDecl>("param")) {
+      if (P->getType()->isRValueReferenceType())
+        return true;
----------------
zeyi2 wrote:

Nit: Seems like redundant code..? IIUC the `TemplateInstantiationPattern` check below already covers the perfect forwarding case.

https://github.com/llvm/llvm-project/pull/180806


More information about the cfe-commits mailing list