<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/147056>147056</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy: cppcoreguidelines-owning-memory doesn't flag double owning
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          denzor200
      </td>
    </tr>
</table>

<pre>
    ```
 gsl::owner<int*> Owner1 = new int(42);
    gsl::owner<int*> Owner2 = Owner1;
    // Owner1 = nullptr;
```

This may lead to double free because following the core guidelines rules we must call `delete Owner1;` and `delete Owner2;` later. 

Another interesting double owning case is regarding move constructors and move assignments:
```
class Foo {
 gsl::owner<int*> ptr=nullptr;
public:
    ~Foo() {
        delete ptr;
 }
    Foo(Foo&& r) : ptr(r.ptr) {
        // r.ptr = nullptr;
    }
 Foo& operator=(Foo&& r) {
        if (&r != this) {
            ptr = r.ptr;
            // r.ptr = nullptr;
        }
        return *this;
 }
};
```

In practice, such kind of wrong code mostly reached due to the fact that people expect `std::move` to set it's pointer argument to `nullptr` but it never do that:
```
    Foo(Foo&& r) : ptr(std::move(r.ptr)) { // BAD
    }
    Foo& operator=(Foo&& r) {
        if (&r != this) {
 ptr = std::move(r.ptr);        // BAD
        }
        return *this;
 }
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVcuuszYQfhpnMzoR2AFOFizIn0bqqpu-gGMP4NbYyJeTpos-e2VDmsv5q9NKvxWB4rl9882ngXuvBoPYkupAquOGxzBa10o0f1pHi2JztvLakrpYf0UHg9eEdYR19mLQEfZNmUBoR9hP8Eu6KYGwIxi8QDa87yihe8IOKRbgy3Caw5dM9yhCT4SengpErefgFpdHgKTofh2Vh4lfQSOXECxIG88aoXeIcEbBo0fordb2oswAYUQQ1iEMUUnUyqAHFzV6uCBM0QcQXGsgdSFRY8AHdHUB3MhXE11Nmgd0W1hAdcaGEV1iBR36kCqvuOzFpH-CewTlweHAnUw3k_1I0IwPLopgnc_V8u0yuQlN8InPZw6E5t7DyVogzeGLoWUSj090zvGslVjSJvb_OllL6Duh-1u-9axN_xMIpDmu5iUkP2tCa3A5mnXZmb67bX6_JlznnK2fx5w9lgpLYrAzOh5s6uA71Z5Sqx5yD7UDQsuUO4zKf_ZL51Z9QclezV-jfEC6HochOgOEdrnsI13p-T0Z_2xgdlwEJZDQb-CjGOF3ZSTYHi7OJsVYiTBZH_QVHHIxogQZMUk-ibrnIkAYeYAZ7awR8I8ZRUhy9UEugkhiSloNFjwGUIHQxsNss0yBuyEmjSUzqYtbn3UB55icweAHOpA2l_ksxP-ghGckd2Wsk7mRfeiOzwq4Zf6xIrhN9F9RscOLCu7A_t_QbyxtZMvknu35BtuyqcqaNRVtNmNbUom8PPeCMl5WNd2XfS9Fw3a8Kat9U29USwtaFU2xK1n1vmu2cl8yLmlVSmS02TOyK3DiSm-1_pi21g0b5X3Ettw1RVVvND-j9nn1Uyo0N8NbUPJKKE2fAtemqLdzHDzZFVr54O95ggoa24cY1oGY57RF70v0bdlrbxNO1l1BWvSG0CZAr_nL7ttEp9sxhDkvs0zsoMIYz1thJ0JPqfD6epud_Q1FIPSUu_GEntaGPlr6dwAAAP__6r74lg">