Some instances of performance-move-const-arg suggest a fix, others do not

I was wondering why I was only seeing performance-move-const-arg fixes apply in some files but not others, so I dug a little deeper and found some instances of the warning suggesting a fix while other source files do not:

warning: std::move of the variable 'message' of the trivially-copyable type 'T' has no effect; remove std::move() [performance-move-const-arg]

and in the other file:

warning: std::move of the variable 'request' of the trivially-copyable type 'T' has no effect [performance-move-const-arg]

There are no compiler errors in either file.

Any hints for determining why?

Hello @IanCollins

A quick look at the source of the check brings me here: llvm-project/MoveConstArgCheck.cpp at 91985c2ee3b3b28b768607f40d1c94a6cbcb29d8 · llvm/llvm-project · GitHub and a blame to [clang-tidy] Fix wrong FixIt in performance-move-const-arg · llvm/llvm-project@a7f8aea · GitHub

If I understand correctly, it has to do with trivially copyable variables. For instance an int does the same when moved and copied. Hence the warning, though, as the function signature required an revalue, it does not remove the std::move.

Personal opinion: this warning in this situation is giving at the wrong location and should be given on the function definition. Such that it is obvious that one should remove the && on it and the declaration. It could give a fixit for that instead. If you cannot update that code, reporting about it makes no sense.

1 Like

FYI: I logged the following bug for it: Clang-tidy: performance-move-const-arg strange failure · Issue #61257 · llvm/llvm-project · GitHub

Thank you for the feedback.

The case where the fix is applied is where the parameter is declared as an rvalue reference

The case where it isn’t applied is a call to std::unorderd_map::insert(), which has two overloads. I’m guessing that is the reason for not removing the std::move.