<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153300>153300</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy: False positive potential memory leak wanring with aggregate initialization of unique_ptr members
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
faedia
</td>
</tr>
</table>
<pre>
When using clang-tidy with the `clang-analyzer-cplusplus.NewDeleteLeaks` check enabled with aggregate initialization of two `unique_ptr` member variables, a false positive memory leak warning is output.
### Reproducer
The code used to reproduce this issue.
```cpp
#include <memory>
struct Foo {
std::unique_ptr<int> a;
std::unique_ptr<int> b;
};
void test_f() {
Foo foo = {std::make_unique<int>(1), std::make_unique<int>(2)};
}
```
#### Steps to reproduce
Run clang tidy with the code above with the `clang-analyzer-cplusplus.NewDeleteLeaks` check enabled, i.e.:
```bash
clang-tidy test.cpp --checks="-*,clang-analyzer-cplusplus.NewDeleteLeaks" -- --std=c++20
```
Actual output:
```
1 warning generated.
test.cpp:11:1: warning: Potential leak of memory pointed to by field '_M_head_impl' [clang-analyzer-cplusplus.NewDeleteLeaks]
11 | }
| ^
test.cpp:9:14: note: Calling 'make_unique<int, int>'
9 | Foo foo = {std::make_unique<int>(1), std::make_unique<int>(2)};
| ^~~~~~~~~~~~~~~~~~~~~~~~
unique_ptr.h:1077:30: note: Memory is allocated
1077 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:9:14: note: Returned allocated memory
9 | Foo foo = {std::make_unique<int>(1), std::make_unique<int>(2)};
| ^~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:11:1: note: Potential leak of memory pointed to by field '_M_head_impl'
11 | }
| ^
```
### Expected result
I would expect no warning to be output, since through all possible code paths, the memory owned by the `unique_ptr` should be deleted.
I have tested this on Ubuntu 25.05:
```bash
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 25.04
Release: 25.04
Codename: plucky
```
With clang-tidy version 20.1.2 installed through `apt` on my ubuntu system:
```bash
$ clang-tidy --version
Ubuntu LLVM version 20.1.2
Optimized build.
```
Also see a reproducer on Godbolt: https://godbolt.org/z/GcMqrb3q1
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVt1v4kYQ_2uWlxHWeo3j8MCDCeF0UnKt7q69R7T2DnibxevbDyh56N9ejQ0JJLkPqVVV5ATjHc_8fvMtvdebFnHG8jnLFyMZQ2PdbC1RaTmqrDrMvjTYQvS63UBtZLsZB60OsNehgdAgsCs-PJatNIdHdOO6M9HTX_IB9ws0GPAO5YNnVxzqBusHwFZWBtWgRG42DjcyIOhWBy2NfpRB2xbsGsLekoHY6q8RV11wpGOL2wod7KTTpMYzcQMS1tJ4hM56HfQOSci6AxiUD7CXriX42oONoYshYbykS2TDBR-xc1bFGt1w8rlBqK1CiB4VBAvuJACh0R609xF7LVd8uOquGzTqtjZRIbDsZsDAsttBqQ8u1gGW1gIr5oyX4INiWcmy8oxgdqPbwLJbkCzrhQC-L1cNcqxYHG94ubNaQUAfVmsmrpmYngyS7TXZzxb06EnvVj7galD-pJiJ65SJKXn3R3KC5J7sF4tzx7xwNXn7U8DOX3iV8fJjbIf8gsv86sMgK7vDfyXniI5OMCE-Zygr6RvGy7MEJ_clddfBeNwr8CxbMCHGTJRM3PyseSFgPIbxuPfgomZizsRc8NcOKusQpTnm5wtwjJfpUxJvsEUnAypKvxNIlpVpSv9YVp4k6fZXG7ClmhoKwa5PddFZ3YYhtasDrDUaBUwUq_tVg1Kt9LYzTBTA8vnPMs0XQ7KmKbDiBoYsgP7T_85vL_FOCe6EQLY2IH3fSGOIIRPF6zyjsB3TrTgqnvaK4T9J6gsif739YfysPpOG-PGiYFmZ8XOa90MEtAdpjK0plGSAZI-EyNAcHIboWrgo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