<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60620>60620</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
libc++-16 regression: unique_ptr no longer works for incomplete type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vogelsgesang
</td>
</tr>
</table>
<pre>
In 16.0.0-rc2, the following code
```
#include <memory>
struct ForwardDeclared;
struct MyStruct {
std::unique_ptr<ForwardDeclared> member;
MyStruct() {}
~MyStruct();
};
```
now produces the error
```
In file included from clang_regression.cpp:1:
In file included from external/clang_linux/include/c++/v1/memory:898:
In file included from external/clang_linux/include/c++/v1/__memory/shared_ptr.h:31:
external/clang_linux/include/c++/v1/__memory/unique_ptr.h:63:19: error: invalid application of 'sizeof' to an incomplete type 'ForwardDeclared'
static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
^~~~~~~~~~~
external/clang_linux/include/c++/v1/__memory/unique_ptr.h:297:7: note: in instantiation of member function 'std::default_delete<ForwardDeclared>::operator()' requested here
__ptr_.second()(__tmp);
^
external/clang_linux/include/c++/v1/__memory/unique_ptr.h:263:75: note: in instantiation of member function 'std::unique_ptr<ForwardDeclared>::reset' requested here
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
^
clang_regression.cpp:7:4: note: in instantiation of member function 'std::unique_ptr<ForwardDeclared>::~unique_ptr' requested here
MyStruct() {}
^
clang_regression.cpp:3:8: note: forward declaration of 'ForwardDeclared'
struct ForwardDeclared;
^
1 error generated.
```
To my understanding, this is in violation of the standard which states:
* https://eel.is/c++draft/unique.ptr#general-4.sentence-3: The template parameter T of unique_ptr may be an incomplete type[.](https://eel.is/c++draft/unique.ptr#general-4.sentence-3)
* https://eel.is/c++draft/unique.ptr#dltr.general-2: The template parameter T of default_delete may be an incomplete type[.](https://eel.is/c++draft/unique.ptr#dltr.general-2.sentence-1)
Afaict, the two mandates:
* https://eel.is/c++draft/unique.ptr#dltr.dflt-3: T is a complete type for `default_delete::operator()(T* ptr) const`
* https://eel.is/c++draft/unique.ptr#single.dtor-note-1: for `~unique_ptr`: [Note 1: The use of default_delete requires T to be a complete type[.](https://eel.is/c++draft/unique.ptr#single.dtor-1.sentence-1) — end note]
do not apply for this code snippet, as I am not calling `~unique_ptr`. The destructor `~MyStruct()` is only declared, but not implemented in the header
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V12P4rgS_TXmpUSUOJDAAw80HxLS3L6j2-hq9ikycSV417EzttM97MP89pWdNNDf0k5PlE5DbJerTp06ZZi1olaICzK9IdP1iHXuqM3iXtcobY2WqXp00Py02ClIsiiO4rEpKaErcEeESkupH4SqodQcSbwm8XJ4ZvFw919pKlQpO45A0lWDjTYnkm6uV1hnutLBVpsHZvgaS8kMcpLevDLpP6e7_gPJh2EAsI6TdEnSZafE9w6L1hmSrl7Y20CDzQHN2TLA2R6hM0LnwWq-Po_-fDp8cSlfXz4_izc8lX6A1mjelWgDXmiMNu_AtFNQCYkwYMWhMrqBUjJVFwZrg9YKraKybUm6THy07yzDHw6NYpLQbW9BCtX9IHQ7TPPvCb0J9_Y-IXT7mJflbD77dONFMZinW3v0qfAJio4kXaaXSH7J7CXvwWyWepDmJF0OuKdLEOqeScGBta0UJXNCK9AVEJpb8TfqitAcnAamfLi6aSU6BHdq0U95TiWanykC1jEnyoJZi8bz5NHcrNi3gVLphqRriH3lEEpLppR2wDFs8HI7Quk10-DFRaabn-fr87Gj85ykS_8HSjvsoQOhrGPKiTNufSVB1akyvPI4PlYhx4p10hV9jK9WYj9Rt2iY02aoLpqDwe8dWoccjmjwGoLCe1hEFkut-OOCWVG4pn2JF5lufgMygVb59Feg-UCg-kkGLbq30Si-7G5WX78Wu9svu9tN8f_d3e5m92W3_-M8svrv7d1-8-3r_4q73e1qU6y-fa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