]> granicus.if.org Git - clang/commit
[analyzer] MoveChecker: Restrict to locals and std:: objects.
authorArtem Dergachev <artem.dergachev@gmail.com>
Mon, 3 Dec 2018 23:06:07 +0000 (23:06 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Mon, 3 Dec 2018 23:06:07 +0000 (23:06 +0000)
commit6a1180062bb720ac29f6a2f02d358e2f058fff40
tree8f2e4d879d8547a88f2406e338d44fe83b1fb658
parent869ef1f57df4f3e8a2cd66dab95438c512b3b7f6
[analyzer] MoveChecker: Restrict to locals and std:: objects.

In general case there use-after-move is not a bug. It depends on how the
move-constructor or move-assignment is implemented.

In STL, the convention that applies to most classes is that the move-constructor
(-assignment) leaves an object in a "valid but unspecified" state. Using such
object without resetting it to a known state first is likely a bug. Objects

Local value-type variables are special because due to their automatic lifetime
there is no intention to reuse space. If you want a fresh object, you might
as well make a new variable, no need to move from a variable and than re-use it.
Therefore, it is not always a bug, but it is obviously easy to suppress when it
isn't, and in most cases it indeed is - as there's no valid intention behind
the intentional use of a local after move.

This applies not only to local variables but also to parameter variables,
not only of value type but also of rvalue reference type (but not to lvalue
references).

Differential Revision: https://reviews.llvm.org/D54557

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348210 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/MoveChecker.cpp
test/Analysis/use-after-move.cpp