================
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=========================
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+ void f(X);
+
+ void g(X x) {
+ f(x); // warning: Could be std::move() [performance-lost-std-move]
+ }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data
flow information.
+Thus, it doesn't catch assign-after-copy cases.
+Also it doesn't notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+ void f(X);
+
+ void g(X x) {
+ auto &y = x;
+ f(x); // emits a warning...
+ y.f(); // ...but it is still used
+ }
----------------
vbvictor wrote:
We can distinguish cases where a variable was an initializer to `VarDecl` of
type `X&` and where the variable was used as a function parameter as
`DeclRefExpr`, https://godbolt.org/z/brKdcsn61.
Even if this can't be fixed, I think it's better to skip cases than have
false-positives for this check.
In your 3-liner example, it may be easy to spot a false-positive, but if `void
g(X x)` is 100+ lines long it will be hard to verify correctness. Thought
`clang-static-analyzer` may [find ](https://godbolt.org/z/d7ed3jYca) these
cases, not everyone use it.
May other reviews share their opinions.
https://github.com/llvm/llvm-project/pull/139525
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits