================
@@ -0,0 +1,42 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-use-after-move %t
+
+#include <utility>
+
+struct Person {
+    Person() = default;
+    Person(Person&&) {}
+};
+
+struct SpecialPerson : Person {
+    int surname;
+    
+    // Valid partial move
+    SpecialPerson(SpecialPerson&& sp) 
+      : Person(std::move(sp)),
+        surname(std::move(sp.surname))
+        // CHECK-NOTES-NOT: [[@LINE-1]]:{{[0-9]+}}: warning: 'sp' used after 
it was moved
+    {}
+
+    // Valid partial forward (The original false positive bug)
+    SpecialPerson(SpecialPerson&& sp, int) 
+      : Person(std::forward<Person>(sp)),
+        surname(std::move(sp.surname))
+        // CHECK-NOTES-NOT: [[@LINE-1]]:{{[0-9]+}}: warning: 'sp' used after 
it was forwarded
+    {}
+
+    // Invalid full move (Must warn)
+    SpecialPerson(SpecialPerson&& sp, float) {
+        SpecialPerson other(std::move(sp));
+        sp.surname = 1;
+        // CHECK-NOTES: [[@LINE-1]]:{{[0-9]+}}: warning: 'sp' used after it 
was moved [bugprone-use-after-move]
----------------
zeyi2 wrote:

```suggestion
        // CHECK-NOTES: [[@LINE-1]]:{{[0-9]+}}: warning: 'sp' used after it was 
moved
```

https://github.com/llvm/llvm-project/pull/199905
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to