[llvm-bugs] [Bug 31234] Should immediately reading from a consumed object provoke a warning?

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 2 10:14:45 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31234

George Burgess <george.burgess.iv at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |george.burgess.iv at gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #1 from George Burgess <george.burgess.iv at gmail.com> ---
Thanks for the report! Looks like clang-tidy's misc-use-after-move check
catches things like this, though. :)

$ cat /tmp/tc.cpp
#include <iostream>
#include <utility>
#include <vector>

int main(int, char**) {
  std::string a("hello");
  std::vector<std::string> x;
  x.emplace_back(std::move(a));

  if (a == "hello") {
    std::cout << "a retains original value" << std::endl;
  }

  return 0;
}

$ ./bin/clang-tidy /tmp/tc.cpp -extra-arg=-std=c++11
-checks=misc-use-after-move
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/tmp/tc.cpp"
No compilation database found in /tmp or any parent directory
json-compilation-database: Error while opening JSON database: No such file or
directory
Running without flags.
1 warning generated.
/tmp/tc.cpp:10:7: warning: 'a' used after it was moved [misc-use-after-move]
  if (a == "hello") {
      ^
/tmp/tc.cpp:8:5: note: move occurred here
  x.emplace_back(std::move(a));
    ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161202/b5726069/attachment.html>


More information about the llvm-bugs mailing list