diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp --- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp @@ -131,6 +131,16 @@ } } } + } else if (const auto *ConstructExpr = dyn_cast(Parent)) { + // Constructor arguments are sequenced if the constructor call is written + // as list-initialization. + if (ConstructExpr->isListInitialization()) { + for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) { + if (ConstructExpr->getArg(I - 1) == S) { + return ConstructExpr->getArg(I); + } + } + } } else if (const auto *Compound = dyn_cast(Parent)) { // Compound statement: Each sub-statement is sequenced after the // statements that precede it. 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 --- 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 @@ -1160,42 +1160,58 @@ } } +namespace { + +struct S1 { + int i; + A a; +}; + +struct S2 { + A a; + int i; +}; + +struct S3 { + S3(); + template S3(int, F); + + int i; + A a; +}; + // An initializer list sequences its initialization clauses. void initializerListSequences() { { - struct S1 { - int i; - A a; - }; - { - A a; - S1 s1{a.getInt(), std::move(a)}; - } - { - A a; - S1 s1{.i = a.getInt(), .a = std::move(a)}; - } + A a; + S1 s1{a.getInt(), std::move(a)}; } { - struct S2 { - A a; - int i; - }; - { - A a; - S2 s2{std::move(a), a.getInt()}; - // CHECK-NOTES: [[@LINE-1]]:27: warning: 'a' used after it was moved - // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here - } - { - A a; - S2 s2{.a = std::move(a), .i = a.getInt()}; - // CHECK-NOTES: [[@LINE-1]]:37: warning: 'a' used after it was moved - // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here - } + A a; + S1 s1{.i = a.getInt(), .a = std::move(a)}; + } + { + A a; + S2 s2{std::move(a), a.getInt()}; + // CHECK-NOTES: [[@LINE-1]]:25: warning: 'a' used after it was moved + // CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here + } + { + A a; + S2 s2{.a = std::move(a), .i = a.getInt()}; + // CHECK-NOTES: [[@LINE-1]]:35: warning: 'a' used after it was moved + // CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here + } + { + // TODO: Note that this is a regression test. + A a; + S3 s3; + s3 = {a.getInt(), [a = std::move(a)] { return a; }}; } } +} // namespace + // A declaration statement containing multiple declarations sequences the // initializer expressions. void declarationSequences() {