Index: clang-tidy/utils/ExprSequence.cpp =================================================================== --- clang-tidy/utils/ExprSequence.cpp +++ clang-tidy/utils/ExprSequence.cpp @@ -144,6 +144,12 @@ // evaluation of the condition. if (S == TheIfStmt->getConditionVariableDeclStmt()) return TheIfStmt->getCond(); + } else if (const auto *TheWhileStmt = dyn_cast(Parent)) { + // While statement: If a variable is declared inside the condition, the + // expression used to initialize the variable is sequenced before the + // evaluation of the condition. + if (S == TheWhileStmt->getConditionVariableDeclStmt()) + return TheWhileStmt->getCond(); } } Index: test/clang-tidy/bugprone-use-after-move.cpp =================================================================== --- test/clang-tidy/bugprone-use-after-move.cpp +++ test/clang-tidy/bugprone-use-after-move.cpp @@ -1132,15 +1132,18 @@ } } -// If a variable is declared in an if statement, the declaration of the variable -// (which is treated like a reinitialization by the check) is sequenced before -// the evaluation of the condition (which constitutes a use). -void ifStmtSequencesDeclAndCondition() { +// If a variable is declared in an if or while statement, the declaration of the +// variable (which is treated like a reinitialization by the check) is sequenced +// before the evaluation of the condition (which constitutes a use). +void ifAndWhileStmtSequencesDeclAndCondition() { for (int i = 0; i < 10; ++i) { if (A a = A()) { std::move(a); } } + while (A a = A()) { + std::move(a); + } } namespace PR33020 {