[PATCH] D67292: [clang-tidy] Fix bug in bugprone-use-after-move check

Martin Böhme via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 00:56:17 PDT 2019


mboehme added inline comments.


================
Comment at: clang-tools-extra/test/clang-tidy/bugprone-use-after-move.cpp:1198
+    }
+  }
   for (int i = 0; i < 10; ++i) {
----------------
gribozavr wrote:
> ymandel wrote:
> > gribozavr wrote:
> > > Unless you think it is redundant, could you also add
> > > 
> > > ```
> > > if (A a1; A(std::move(a2)).getInt() > 0) {}
> > > ```
> > > 
> > > Also some true positive tests would be good:
> > > 
> > > ```
> > > if (A a1; A(std::move(a2)).getInt() > A(std::move(a2)).getInt()) {}
> > > ```
> > > 
> > > ```
> > > A a1;
> > > if (A a2 = std::move(a1); A(std::move(a1)) > 0) {}
> > > ```
> > Done, but any idea why everything in this function is placed inside a loop?  Looks like its just for scoping, but then why not just a compound statement, as is done above? This feels very odd.
> I think it is to ensure that the checker understands the sequencing. If it didn't, then the loop would trigger the "moved twice" logic.
(Original author of the test here.)

Correct. I should probably have added a comment explaining this when I wrote the test. Feel free to add such a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67292





More information about the cfe-commits mailing list