[clang-tools-extra] [clang-tidy] Prevent false-positive in presence of derived-to-base cast in bugprone.use-after-move (PR #189638)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 11 02:47:16 PDT 2026


================
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-use-after-move %t
+
+#include <utility>
+
+struct A {
+  int a;
+};
+
+struct B : A {
+  int b;
+  B(B&& other) :
+    A(std::move(other)),
+    b(std::move(other.b))
+      // CHECK-NOTES-NOT: [[@LINE-1]]:7: warning: 'other' used after it was moved
+        {}
----------------
localspook wrote:

Can we add a test like:
```suggestion
  int b;
  void f();
  B(B&& other) :
    A(std::move(other)),
    b(std::move(other.b))
      // CHECK-NOTES-NOT: [[@LINE-1]]:7: warning: 'other' used after it was moved
        {
          other.f();
          // CHECK-NOTES: [[@LINE-1]]:11: warning: 'other' used after it was moved
          // CHECK-NOTES: [[@LINE-6]]:7: note: move occurred here
        }
```
To constrast how accessing a derived member variable after moving the base is okay, but calling a derived member function isn't.

https://github.com/llvm/llvm-project/pull/189638


More information about the cfe-commits mailing list