<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123637>123637</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Bad error trace for issue with unique_ptr
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JVApen
</td>
</tr>
</table>
<pre>
The following is reduced from a build with clang-cl and the MS stl implementation:
````
#include <vector>
#include <memory>
#include <type_traits>
template <class _Ty>
struct ms_default_delete { // default deleter for unique_ptr
constexpr ms_default_delete() noexcept = default;
template <class _Ty2, std::enable_if_t<std::is_convertible_v<_Ty2*, _Ty*>, int> = 0>
ms_default_delete(const ms_default_delete<_Ty2>&) noexcept {}
void operator()(_Ty* _Ptr) const noexcept /* strengthened */ { // delete a pointer
static_assert(0 < sizeof(_Ty), "can't delete an incomplete type");
delete _Ptr;
}
};
struct FWD;
struct S
{
~S() = default;
std::vector<std::unique_ptr<FWD, ms_default_delete<FWD>>> member;
};
int main(int, char**){
S s;
}
````
https://compiler-explorer.com/z/6K8ebK3E1
This gives the error:
````
<source>:13:27: error: invalid application of 'sizeof' to an incomplete type 'FWD'
13 | static_assert(0 < sizeof(_Ty), "can't delete an incomplete type");
| ^~~~~~~~~~~
/opt/compiler-explorer/clang-trunk-20250120/bin/../include/c++/v1/__memory/unique_ptr.h:300:7: note: in instantiation of member function 'ms_default_delete<FWD>::operator()' requested here
300 | __deleter_(__tmp);
| ^
/opt/compiler-explorer/clang-trunk-20250120/bin/../include/c++/v1/__memory/unique_ptr.h:269:71: note: in instantiation of member function 'std::unique_ptr<FWD, ms_default_delete<FWD>>::reset' requested here
269 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
| ^
/opt/compiler-explorer/clang-trunk-20250120/bin/../include/c++/v1/__memory/construct_at.h:66:11: note: in instantiation of member function 'std::unique_ptr<FWD, ms_default_delete<FWD>>::~unique_ptr' requested here
66 | __loc->~_Tp();
| ^
<source>:17:8: note: forward declaration of 'FWD'
17 | struct FWD;
| ^
1 error generated.
````
In this trace, this mentions the location of the `static_assert`, it mentions the location of the forward declare.
Though what is missing in this trace is the location that started the initialization. (The inline destructor of struct `S`)
This last is especially useful if you have the output of multiple compilations together without explicit mention of the file that was compiled.
(Like a multi-process build via CMake, a CI system that runs clang-tidy on multiple files and puts all results together ...)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEV09v47oR_zT0ZRBDJm3LPvggKzaavrfvBS9BuzeBlsYWuxSpJUfOZg_57AUp2Y437h5aoCsQCMIh589vZn4cS-_VwSCu2GzNZvcj2VFt3erv_8haNKOdrV5XzzXC3mptX5Q5gPLgsOpKrGDvbAMSdp3SFbwoqqHU0hzuSg3SVEA1wqcn8KRBNa3GBg1JUtYwkbEkrnlyWUnGuFCm1F2FwER-xJKsY2LzQdJgY93rLQm9tliQk4r8IE4ywqbVkqK81NJ7KJ6Hy55cVxI0vqhwLztNRYUaw9F0DYxvGd_CIIFe4mBvHXRGfe2waMmxJAMAKK3xhN9a91EX4wvGl2AsfiuxJWDi_qSTiXXvYlBx003OeA6eqoCYyNDIncZC7QtiIj9vK1-U1hzRkQriIxN5fzULt0OwPAvx8hyUISY20Yekh-CmwzGcG5JBcdA1vw4qXbP0_hLM0aoKbItOhhRGBBhf9K5A8Ugu3O6tXHQEvDPw5NAcqEaDFcQYttfpiAmS0FplCE8JCJ8P1VUW0nt0xPgiCVCCV9_R7k_WlwEFxnkpDeMpndUZUKa0oUoJIVQR4zycjhk6GRgOR__PgiHu9L7fGkpq-8_7c3aHrad4LF57exqq4kMx9HEMiT11wCXV7wpP5MEGz2-mKZrf9AsabHY4eHz2s1_KEDRSGcYXoTR4DmUtXUQ9C-GnJ5-ewF8UfGjcmqj1wcOYo4Cj0uju8FurrUM3Lm3D-PY749v5bwvc_SY2k97-c608HNQRfWQLd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