<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54365>54365</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Bug in either C++17 (maybe 20?) spec, or llvm implementation, shared_ptr
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
timprepscius
</td>
</tr>
</table>
<pre>
Hey there,
I'm not sure where to post this, I feel like I should be posting to some spec committee. Not sure.
In the Xcode 12.5.1 std memory, there is the snippet:
```
template <class _Tp, class _Alloc>
void
__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
{
__data_.second().~_Tp();
}
```
What this snippet does, is when a control block of a shared_ptr detects that there are no more references, it destructs/destroys the object.
Right now the code snippet calls the destructor explicitly, which leaves out the exciting things the allocator might do before destructing the object.
I believe this code snippet should be something like this (writing off the top of my head):
```
using value_allocator = _Alloc::template rebind<the_value_type>::other;
value_allocator allocator;
allocator.destroy(&__data_.second());
```
Or using allocator_traits, or what not. But in the end, not calling the destructor, but rather using the allocator to call the destructor.
---
If this were the case I could write an allocator which might do something like:
```
void destroy(T *p)
{
object_is_about_to_be_destroyed_template_function(p);
other_allocator.destroy(p);
}
```
---
Should I take this issue somewhere else? Does anyone know who I might talk to about this.
---
There is, of course, a work around, but it isn't pretty, and uses classes which I probably should be using.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVctu4zgQ_Br50oighx_xwYfYSTC5zAx2A-zcBEpqWdxQokBS8Xq_frtJ-RVkgg0MhZK6q5tdxVKp6-PmGx7BtWgwynZR8hglD-H6EmWrDnrtwI4G4cAh4DQM2jpKkJbi4QUaRAVKviGtbatHVUOJPkj2e463ukOwA1ZQ6a6TziHGAN8n3PimZM-dwK9K1whpFi_iFKyrocNOmyPX842CtD7O9nIY0EX5lB4tk-l3hemwG5RwCFG-q5SwForXg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