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

    <tr>
        <th>Summary</th>
        <td>
            clang-analyzer-cplusplus.NewDeleteLeaks when a tuple of a unique_ptr is captured in lambda
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    ### Observation

Both `clang-tidy` and `scan-build` warn about a potential memory leak in this code, which looks like a false positive:

```cpp
#include <tuple>
#include <memory>

int main()
{
    auto lambda = [tuple = std::make_tuple(std::make_unique<int>(42))] {};
}
```

```
$ clang-tidy main.cpp -checks="clang*"
1 warning generated.
/foo/main.cpp:7:1: warning: Potential leak of memory pointed to by field '_M_head_impl' [clang-analyzer-cplusplus.NewDeleteLeaks]
}
^
/foo/main.cpp:6:44: note: Calling 'make_unique<int, int>'
    auto lambda = [tuple = std::make_tuple(std::make_unique<int>(42))] {};
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/unique_ptr.h:962:30: note: Memory is allocated
    { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/foo/main.cpp:6:44: note: Returned allocated memory
    auto lambda = [tuple = std::make_tuple(std::make_unique<int>(42))] {};
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
/foo/main.cpp:7:1: note: Potential leak of memory pointed to by field '_M_head_impl'
}
^
```

### Expected Behaviour

No warning is issued for this code.

### Additional Details

Environment: Fedora 35, clang 13.0.0, gcc 11.3.1.

Compile commands:

```json
[
{
  "directory": "/foo",
  "command": "/usr/bin/g++ -std=c++17 /foo/main.cpp",
  "file": "/foo/main.cpp"
}
]
```

Note, the issue is reproducible with `-std=c++17` and `-std=c++20`, but not with `-std=c++14`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVsuSqzYQ_Rq8UZkCAcZeeOHHzCp3kkpl7xKobTQWiEjCHufr0xLGrzu-NamkkkVcIINo9escdatQ_DQPaNJf5OfCgD4wK1QTROsgWvTjUtmKBJOolKzZja3gJ3whrOFu0pSsGRedkNxNHpluCCtUZwkjrbLQWMEkqaFW-kQksD0RDbGVMKRUHAK6IsdKlBWRSu0NkWIPuHDLpAFcboQVBwiSxa03aKa_yrY9z9BENKXsOJAgWdmulbjm5bNvvR_Xj34UjSU1E01ApwGdnb_ky_6B4I91VhHJ6oIzVLImQbb0RvyLsdw5mCxqtodNb5xO72e7RvzeoU8rNOWM02lKnSm8MlSHtvJ1kCwH0-uHQD-NfggvJVdYfBgh5oWMywrKvUEHA0q9QEBRmParYo-TaHZkBw1oZoGHg77XrVI4DpowhBzvGO9hkXv85QKtx1RtB4hbhTECJ5ix4kS2AiSyhOabb5sKGN-IupX46lLYu80aJk9_gB6XreyMu8M3OK5BgoWfULXBDD3mJXt57uwE7zR1LjboovtfMSldqGj2ezCQfwMm-X8FOPn6z4We_0PXkMLOaBwLx__XMMRBigLHXVni-DGdbCbpWAOvmB1jHrsPnI3jQfZhOG81fMLFS3_1woWwxtnyedm0VocV5mo2oTgm0S1c33oeYYFA3FTpuHlNE2aOaLAdFpmrKkzz5re2T3MDR-JebgDZKo3E5U5qoXeml9tsmHums9D57YFJluRCsX8NhL8O1xcY_6vPEG7CSwbPu_N_yvDnFW3I2N8sZ08L1KcV_NJuXz5aKJ32JVTsIFSnb-Xe1KVK42YQxnQoiWS-ds_wc7ULzoVr4RjNGiwT0tzKvTQHoVVTg8NtQV6BK81IkrlS6EsyiZMwCiP3jjWAxHGYhPGdqZWqW4FcKVVd4ynAPGvQ7-Zyjsguze1CCexGXGhMgCMmdYXATQ1w4cPqRvJs6k7utnDt-nJDxp6l63P1ibH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