<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/89293>89293</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `__is_trivially_equality_comparable(T)` false positive when the defaulted operator is ineligible
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          AMP999
      </td>
    </tr>
</table>

<pre>
    Clang's `__is_trivially_equality_comparable(T)` builtin assumes that if a type has _any_ defaulted trivial comparison operator, then _all_ its comparison operators will be tantamount-to-trivial. That's a sane assumption... but only if the defaulted operator is actually eligible for the given `T`! If the defaulted operator is `requires`-clause'd away, then we shouldn't consider it relevant to the question of triviality at all.
https://godbolt.org/z/3hs4EKPKT
```
template<bool B>
struct S {
    int i;
    bool operator==(const S&) const requires B = default;
    bool operator==(const S& rhs) const { return (i % 3) == (rhs.i % 3); }
};
static_assert(__is_trivially_equality_comparable(S<true>)); // OK
static_assert(not __is_trivially_equality_comparable(S<false>)); // Oops, this line assert-fails
```
This compiler misbehavior causes libc++ to miscompile `std::equal`:
https://godbolt.org/z/YPfEG6cv9
```
    S<false> a[] = {1,2,3};
    S<false> b[] = {4,5,6};
    return std::equal(a, a+3, b, b+3);
      // should be true, not false
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVUFv8jgQ_TXDZQQK45CQA4cGympVrbZSe9kTmiSGeGViak-o2F-_cgJtv273Uz8paok98zzvzcuYQzCHTusVLEpYbCbcS-v86u6Px6IoJpVrLqu15e4AlAeELNntTNiJN2fD1l52-qVna-Syq93xxJ4rq4GWz0AFZAlWvbFiOuQQ-qMOKC0Lmj0yyuWkseWAO-4uO2z0nnsrusErNI54JrgO3Ul7FueB1iit7nDH1u7QSPgqKuCrsRYrjcKd8NH1nUzFTa_AM3xuWQY2jIE7PRZ3EuO62WyG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