<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111185>111185</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
c++23: constexpr std::unique_ptr::~unique_ptr()/std::default_delete<T> instantiation too strict
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jdrouhard
</td>
</tr>
</table>
<pre>
```cpp
#include <memory>
class Foo {
inline static std::unique_ptr<Foo> instance_;
};
```
See: https://godbolt.org/z/MqMxs9nzr
This fails to compile due to `unique_ptr<T>::~unique_ptr()` (and thus `default_delete<T>::operator()`) being instantiated at the point of the variable declaration (when the class isn't fully defined yet). Since c++23, `unique_ptr` and `default_delete::operator()` are constexpr, but the declaration of the unique_ptr should not attempt to fully instantiate the destructor or std::default_delete<T>::operator() yet. Or at least the above usage pattern should be allowed, as this is a valid pattern for singletons (that aren't Meyers style). Should this fall back to non-constexpr unique_ptr/default_delete?
This fails using both libc++ and libstdc++. gcc and msvc both compile it fine.
```
In file included from test.cpp:1:
In file included from /builds/clang-19.1.0/bin/../include/c++/v1/memory:944:
In file included from /builds/clang-19.1.0/bin/../include/c++/v1/__memory/inout_ptr.h:16:
In file included from /builds/clang-19.1.0/bin/../include/c++/v1/__memory/shared_ptr.h:32:
/builds/clang-19.1.0/bin/../include/c++/v1/__memory/unique_ptr.h:78:19: error: invalid application of 'sizeof' to an incomplete type 'Foo'
78 | static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
| ^~~~~~~~~~~
/builds/clang-19.1.0/bin/../include/c++/v1/__memory/unique_ptr.h:292:7: note: in instantiation of member function 'std::default_delete<Foo>::operator()' requested here
292 | __ptr_.second()(__tmp);
| ^
/builds/clang-19.1.0/bin/../include/c++/v1/__memory/unique_ptr.h:261:71: note: in instantiation of member function 'std::unique_ptr<Foo>::reset' requested here
261 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
| ^
simple.cpp:4:38: note: in instantiation of member function 'std::unique_ptr<Foo>::~unique_ptr' requested here
4 | inline static std::unique_ptr<Foo> instance;
| ^
simple.cpp:3:7: note: definition of 'Foo' is not complete until the closing '}'
3 | class Foo {
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk1v27oS_TX0ZhBBomxLWnjh2BFegJe2aLLoTqCkscU-mlRJyq276G9_GEn-iK9TXNx7c40gtiiSc87h8MwI5-RWIy7Y7J7N1hPR-cbYxdfamq4Rtp6Upj4s2Dwc_qq2ZeGahUvGY6kr1dUILF7tcGfsgcUP48v-f6WEc5AbAyy5H4YApFZSIzgvvKzA-ZrFSxYvOy2_dVi03rJ4lRvD4geQ2nmhKyxYPC5nyfr8-wjpMuQzIouX0HjfOtqY54znW1OXRvnA2C3j-U_G86dvTz9cpn_ay7UvjXSwEVI58AYqs2ulQqg7pEc2D19BfCGuPfJfF-M8ZTxj8xAYT4WuwTedo6U1bkSnfFGjQo-vlpsWrfDmvJbxDEqUejvy91J4rEF48A1Ca6T2YDb9w15YKUoCiZUSVnhpNIX-3qDuJwwnIJ1mPPGw6ZQ6QI0bqbGGA3rGswCepa4QKsbvGb_nMeOrK7LzEIjLDRo38YOwCJXRzuOP1tJ2ZTdgv0Q5MjiHAdeYTtWgjQfhPe5aT7oPmC-UGHdy3naVNxaMPSfRn5aZyAfw0ZKqCoUb8InS7BE6J7YILWGw-oiqRBBKme9YEyHhwFOySAcC9kLJ-jR_Q3ik3ir0Rjs6DN8IT5oMZ_CEB7QOnD8oHOQfAvgh-ZSCUlT_I-ba6LuTjHCZZPk1z_yNNO4ICZTGN6BkOR5xf5hKls7X40gA26rqh3duXw3zj-kvPVC6BJcRrm7eo4ZNP3Wwgxo21uzAo_MBuUW8jOgIfjOV8bzspKod43mlhN7eRVkQBSGNS814HgSM5-MamjPAZjzfR4znR-9ZZtPp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