[PATCH] D74692: [clang-tidy][bugprone-use-after-move] Warn on std::move for consts

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 6 06:05:01 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:383
   SourceLocation MoveLoc = MovingCall->getExprLoc();
+  const bool MoveArgIsConst = MoveArg->getType().isConstQualified();
 
----------------
Drop the top-level `const` and make it an integer type so that you don't need to use the `?:` below. The implicit conversion will do the right thing in terms of the integer value.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:391-392
+    if (Lambda) {
+      for (auto Capture = Lambda->capture_begin(), End = Lambda->capture_end();
+           Capture != End; ++Capture) {
+        if (MoveArg->getDecl() == Capture->getCapturedVar()) {
----------------
Range-based for loop over `captures()`?


================
Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:394
+        if (MoveArg->getDecl() == Capture->getCapturedVar()) {
+          const bool IsExplicitCapture = Capture->isExplicit();
+          Check->diag(
----------------
Same suggestions here as above.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:342
+      // CHECK-NOTES: [[@LINE-5]]:20: note: variable 'a' implicitly captured const here
     };
   }
----------------
One more test case to try out (it might be a FIXME because I imagine this requires flow control to get right):
```
A a;
std::move(a);

auto lambda = [=] {
  a.foo(); // Use of 'a' after it was moved
}
```


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

https://reviews.llvm.org/D74692





More information about the cfe-commits mailing list