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

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 10 18:50:07 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;
----------------
HerrCai0907 wrote:

when P is rvalue ref, it is also possible that P is a normal `T&&` instead of perfectly forwarded argument

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


More information about the cfe-commits mailing list