[clang-tidy] Fix `bugprone-use-after-move` check to also consider moves in constructo...
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>
Mon, 15 Nov 2021 07:28:46 +0000 (07:28 +0000)
committerCarlos Galvez <carlosgalvezp@gmail.com>
Mon, 15 Nov 2021 07:41:35 +0000 (07:41 +0000)
commitc3e3c762098e8d425731bb40f3b8b04dac1013f3
tree1685a42021a318333cc0e485dd62ec1718495bf3
parentd5730647accf0986fa994f5b930b87de1c99eb24
[clang-tidy] Fix `bugprone-use-after-move` check to also consider moves in constructor initializers

Fixes PR#38187. Constructors are actually already checked,
but only as functions, i.e. the check only looks at the
constructor body and not at the initializers, which misses
the (common) case where constructor parameters are moved
as part of an initializer expression.

One remaining false negative is when both the move //and//
the use-after-move occur in constructor initializers.
This is a lot more difficult to handle, though, because
the `bugprone-use-after-move` check is currently based on
a CFG that only takes the body into account, not the
initializers, so e.g. initialization order would have to
manually be considered. I will file a follow-up issue for
this once PR#38187 is closed.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D113708
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp