<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107610>107610</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang crashes while generating operator<=>
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sabudilovskiy
</td>
</tr>
</table>
<pre>
```cpp
#include <compare>
#include <optional>
template <typename T>
struct box {
T* ptr = nullptr;
friend constexpr std::strong_ordering operator<=>(const box<T>& lhs, const box<T>& rhs) noexcept {
if (lhs.ptr && rhs.ptr) {
return *lhs.ptr <=> *rhs.ptr;
}
if (lhs.ptr) {
return std::strong_ordering::greater;
}
if (rhs.ptr) {
return std::strong_ordering::less;
}
return std::strong_ordering::equal;
}
friend bool operator==(const box<T>& lhs, const box<T>& rhs);
};
struct TreeNode {
std::optional<box<TreeNode>> children;
constexpr std::strong_ordering operator<=>(const TreeNode&) const;
};
constexpr std::strong_ordering TreeNode::operator<=>(const TreeNode&) const = default;
```
https://godbolt.org/z/71fenezqW
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVEtv4y4Q_zTjy6gRhsSPgw95NMf_qdL_uML2xGaXgAu42_bTr3DSxK3abndXshLBzO_BzID0XnWGqILVBla7RI6ht67ysh5bpe2D_6Gektq2TxVk7PQ1wwBsB2wNXCjT6LElBLFt7HGQjkDcvhe1Q1DWSH0NT7-BjoOWYUoJTwMZeSS8uyT54MYmYG0fEfLNaQ_xDvgah-AQxA7NqPUQHIjNnBfx4BSZFhtrfKDHwaEPLYg1iEhqTffNupacMh3agZwM1oHYgthFbV5MsKgLYjvZ4Rnq3gPf4nshF0MlGkuPDQ1hbhZRHRB4oXu_mDzz7IyIy4h6lYzoKIzOIPD1BfJiLG6-AMUMBPnuvHil9TH5R7U4bXaOZKDPJX7r_3MJTd5_wP8lPN2PcZYuBBf4m_bX1upZg3fx-8vuXics372ZtvOY3jmi_2yc93lFLge5XoHtmf-cH2XELTa90q0jA2KDV_g_DfBFIQ5deeL65Bxf0Lp6Ph3pT5Sn-9rSQY565uLlWZkb6UMYfJTge-D7zra11WFhXQd8_wx8n6cHMvR8_3_SVqItRSkTqtKcr7IlX6ZZ0ld5XRzaImMkDzIrRXtggqUk2KouZcN4maiKM75kJcvSnGWrbJEWsiiIFas8L3laZ7BkdJRKL7R-OEbtRHk_UpWyPEtZomVN2k_PJueNlqYDzuML6qoIuKnHzsOSaeWDv1IEFTRV25iOjZO-J48_e6UJOzKxlu_2E5PR6epNUVTox3rR2CPwfeQ__90Mzn6nJgDfT3498P3Z8kPFfwUAAP__kOnDDA">