[clang-tools-extra] [clang-tidy] Don't suggest const on `std::moved` locals in templates … (PR #226577)

Daniel Petrovic via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 05:40:28 PDT 2026


================
@@ -199,6 +199,25 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
   }
 }
 
+static bool isStdMoveOperandInTemplate(const VarDecl *Variable,
+                                       const FunctionDecl *Func,
+                                       ASTContext &Context) {
+  if (Func->isTemplateInstantiation())
+    if (const Stmt *Body = Func->getBody()) {
+      // Match on the instantiated body where `std::move` is resolved to a
+      // concrete function and the argument references the instantiated
+      // variable.
+      const auto Moves =
+          match(stmt(forEachDescendant(
+                    callExpr(callee(functionDecl(hasName("std::move"))),
+                             hasArgument(0, ignoringImpCasts(declRefExpr(
----------------
daniel-petrovic wrote:

> Could we use `ignoringParenImpCasts` here?

Thanks for the hint.  I think (and it looks like we could, but there seems to be no difference). I tested `std::move((tmp))` but both `ignoringImpCasts` and `ignoringParenImpCasts` match it. Is there a specific case you're thinking of where `ignoringParenImpCasts` would be needed here ?

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


More information about the cfe-commits mailing list