diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp index 136d8f862b95..064b6ae19784 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -129,8 +129,12 @@ bool UseAfterMoveFinder::find(Stmt *FunctionBody, const Expr *MovingCall, Visited.clear(); const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall); - if (!Block) - return false; + if (!Block) { + // This can happen if MovingCall is in a constructor initializer, which is + // not included in the CFG because the CFG is built only from the function + // body. + Block = &TheCFG->getEntry(); + } return findInternal(Block, MovingCall, MovedVariable, TheUseAfterMove); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp index 73ca59ccc91b..e26db0f6793e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp @@ -1338,3 +1338,15 @@ void typeId() { Foo Other{std::move(Bar)}; } } // namespace UnevalContext + +class PR38187 { +public: + PR38187(std::string val) : val_(std::move(val)) { + val.empty(); + // CHECK-NOTES: [[@LINE-1]]:5: warning: 'val' used after it was moved + // CHECK-NOTES: [[@LINE-3]]:30: note: move occurred here + } + +private: + std::string val_; +};