[PATCH] D107450: [clang-tidy] Fix wrong and missing warnings in performance-move-const-arg

gehry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 4 05:19:29 PDT 2021


Sockke created this revision.
Sockke added reviewers: alexfh, aaron.ballman, whisperity, steven.zhang, MTC.
Herald added subscribers: rnkovacs, xazax.hun.
Sockke requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

There are incorrect Fixit and missing warnings:
case 1:
A trivially-copyable object wrapped by std::move is passed to the function with rvalue reference parameters. Removing std::move will cause compilation errors.

  void showInt(int&&) {}
  void testInt() {
      int a = 10;
      // expect: warning + nofix
      showInt(std::move(a));  // showInt(a) <--- wrong fix
  }
  
  struct Tmp {};
  void showTmp(Tmp&&) {}
  void testTmp() {
      Tmp t;
      // expect: warning + nofix
      showTmp(std::move(t));  // showTmp(t) <--- wrong fix
  }

case 2:
Using std::move() to wrap a pure rvalue or expiring value has no effect. Remove std::move().
The object returned in the function does not need to be wrapped with std::move. Because the returned nontrivially-copyable object will first call its own move constructor.

  struct TmpNR {
      TmpNR() {}
      TmpNR(const TmpNR&) {}
      TmpNR(TmpNR&&) {}
  };
  void showTmpNR(TmpNR&&) {}
  TmpNR testTmpNR() {
      TmpNR tnr;
      // expect: warning + fixit
      TmpNR tnr2 = std::move(TmpNR()); //  no warning <--- wrong diagnosis
      // expect: warning + fixit
      return std::move(tnr);  //  no warning <--- wrong diagnosis
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107450

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance-move-const-arg.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107450.364062.patch
Type: text/x-patch
Size: 7058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210804/5c81923e/attachment-0001.bin>


More information about the cfe-commits mailing list