<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67056>67056</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Compare operator not defined for recursive data types on C++20
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zasdfgbnm
</td>
</tr>
</table>
<pre>
Cross-posting https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111504
The following code works on C++17 but not C++20:
```C++
#include <cstdint>
#include <type_traits>
#include <vector>
template <typename T1, typename T2>
static auto hasLessThanHelper(int)
-> decltype(std::declval<T1>() < std::declval<T2>(), std::true_type{});
template <typename, typename>
static auto hasLessThanHelper(long) -> std::false_type;
template <typename T1, typename T2>
struct hasLessThan : decltype(hasLessThanHelper<T1, T2>(0)) {};
struct DynamicType {
using T1 = int64_t;
using T2 = std::vector<DynamicType>;
};
template <
typename DT,
typename = std::enable_if_t<
(hasLessThan<typename DT::T1, typename DT::T1>::value ||
hasLessThan<typename DT::T1, typename DT::T2>::value ||
hasLessThan<typename DT::T2, typename DT::T1>::value ||
hasLessThan<typename DT::T2, typename DT::T2>::value)>>
inline constexpr bool operator<(const DT& x, const DT& y) {
// implementation omitted
return true;
}
int main() {
using DT = DynamicType;
// This assert works on C++17, but fails on C++20
static_assert(hasLessThan<std::vector<DT>, std::vector<DT>>::value);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU2P4ygQ_TXkgjqyi3z54EO3M9Ee9uh7hKHssIvBAtw9mV-_giRuJ53ZWa12W5ZbqSq_evV4APdedQaxJOs3st4v-BhO1pU_uJdt15h-0Vh5LitnvX8ZrA_KdPQUwuAJeyVwIHDohFh2Zlxa1xE4NGP3Q2nNCRz8yX4cm7Fbik4RdlCSsH2e5-tsRbI9yV4v7_qEtLVa248ILaxE-mHdn55aQysCbwTe8i1txkCNDbcIZ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