https://github.com/flovent updated https://github.com/llvm/llvm-project/pull/197438
>From bf4b01f211deea5246348eceb0a28cc27825c31f Mon Sep 17 00:00:00 2001 From: flovent <[email protected]> Date: Wed, 13 May 2026 21:10:39 +0800 Subject: [PATCH 1/2] [clang-tidy] Fix false positives about reinitialization detection in `bugprone-use-after-move` --- .../clang-tidy/bugprone/UseAfterMoveCheck.cpp | 3 ++- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ .../checkers/bugprone/use-after-move.cpp | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp index 31c70b3643be6..7fd810554804f 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -132,7 +132,8 @@ makeReinitMatcher(const ValueDecl *MovedVariable, // operator, test for built-in assignment as well, since // template functions may be instantiated to use std::move() on // built-in types. - binaryOperation(hasOperatorName("="), hasLHS(DeclRefMatcher)), + binaryOperation(hasOperatorName("="), + hasLHS(ignoringImpCasts(DeclRefMatcher))), // Declaration. We treat this as a type of reinitialization // too, so we don't need to treat it separately. declStmt(hasDescendant(equalsNode(MovedVariable))), diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index edcf490433f7f..2024cec8f026d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -430,6 +430,9 @@ Changes in existing checks - Avoid false positives when moving object to a base type then accessing non-base members. + - Avoid false positives when moving object is reinitialized via the base + class's ``operator=``. + - Improved :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines <clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines>` check by adding the `AllowExplicitObjectParameters` option. When enabled, 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 80df2b99eb874..65b7f8f1d619c 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 @@ -1790,3 +1790,20 @@ void Run() { db6.Query(); } } // namespace custom_reinitialization + +namespace GH62206 { + struct Base { + + }; + + struct Derived: public Base { + using Base::operator=; + }; + + void foo() { + Base b; + Derived d; + std::move(d); + d = b; // Should not warn + } +} >From 6b4d1ce38ee04dbd9d1207a49abdf26a6e07fd74 Mon Sep 17 00:00:00 2001 From: flovent <[email protected]> Date: Wed, 13 May 2026 22:20:35 +0800 Subject: [PATCH 2/2] Update clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp Co-authored-by: Zeyi Xu <[email protected]> --- .../test/clang-tidy/checkers/bugprone/use-after-move.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 65b7f8f1d619c..bc38d2b3a484c 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 @@ -1806,4 +1806,4 @@ namespace GH62206 { std::move(d); d = b; // Should not warn } -} +} // namespace GH62206 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
