[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

Aaron Gokaslan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 15 08:02:41 PST 2023


Skylion007 added a comment.

In D137205#4054534 <https://reviews.llvm.org/D137205#4054534>, @Febbe wrote:

> In D137205#4047828 <https://reviews.llvm.org/D137205#4047828>, @Skylion007 wrote:
>
>> I am trying this in the wild and getting some false positives where it tries to call std::move inside loop conditions and in the boolean condition for an if statement. Stuff like:
>>
>>   if (SmartPtr new_ptr = steal_ptr(std::move(old_ptr))) {
>>     ...
>>   }
>>   else {
>>     return old_ptr; // Now it's moved from and invalid
>>   }
>>
>> Also this can be happen for similar boolean conditionals in while, for, do while loops.
>>
>> Interestingly, the logic in bugprone-use-after-move flags this error so maybe we can reuse some of that logic to detect bad std::move.
>
> Does this only happen on "init-statements" of while/if/switch?
> And thanks for the catch, I'll take a look into it as soon I have more time.
>
> Btw. I've oriented myself at the "bugprone-use-after-move" check, but simply inverting it does not work here.

It happens in any conditional statements.

Another common failure case

  while(shouldStop(std::move(a))){
      // doSomething
      // a is last usage, but shouldStop called multiple times
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205



More information about the cfe-commits mailing list