<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122405>122405</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] False positive diagnostic for NewDeleteLeaks
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy,
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ChuanqiXu9
</td>
</tr>
</table>
<pre>
Reproducer:
```C++
#include <vector>
#include <memory>
void RuleParseCommon() { std::vector{std::make_shared<int>()}; }
```
Reproducer reduced by cvise:
```C++
namespace std {
template <class E> struct initializer_list {
const E *begin;
const E *end;
};
template <typename _Tp> struct vector {
vector(initializer_list<_Tp>);
};
struct _Sp_counted_base {};
struct __shared_count {
__shared_count(int, int) {
auto __pi = new _Sp_counted_base;
_M_pi = __pi;
}
~__shared_count();
_Sp_counted_base *_M_pi;
};
int _M_ptr;
struct __shared_ptr {
template <typename _Alloc>
__shared_ptr(_Alloc __tag) : _M_refcount(_M_ptr, __tag) {}
__shared_count _M_refcount;
};
struct shared_ptr : __shared_ptr {
shared_ptr(int __tag) : __shared_ptr(__tag) {}
};
int allocate_shared___a;
shared_ptr allocate_shared() { return allocate_shared___a; }
shared_ptr make_shared() { return allocate_shared(); }
} // namespace std
using std::vector;
void RuleParseCommon() { vector{std::make_shared()}; }
```
Command:
```
clang-tidy test.cc -checks='clang-analyzer-cplusplus.NewDeleteLeaks' -- -std=gnu++20
```
we got:
```
Potential leak of memory pointed to by field '_M_pi' [clang-analyzer-cplusplus.NewDeleteLeaks]
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVUuP6jYU_jVmcwTK2ITAIosAw6qtrm676C5ynJPgjmOntsOIu-hvr5yER4DeqRRkyY_vZZ8Dd07WGjEl8ZbE-xnv_NHYdHfsuP5b_tltZoUpz-l3bK0pO4GWsIxE_beKhm9H6DZ8UUYok1qorkQgbH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