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

    <tr>
        <th>Summary</th>
        <td>
            comparison operators for std::pair are not SFINAE-friendly in C++17 mode
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          EwgenijGawrilow-TomTom
      </td>
    </tr>
</table>

<pre>
    operator==, operator< and other comparison operators defined for std::pair accept two arbitrary pairs as operands, even if their members are in fact not comparable.  The inconsistency is detected only during the instantiation, which thwarts any generic application code relying on SFINAE.

An example:
```
bool compare_pairs(const std::pair<long,long>& p1, const std::pair<std::pair<long,long>, long>& p2) { return p1 < p2; }
```
rightfully fails to compile, while
```
auto compare_pairs(const std::pair<long,long>& p1, const std::pair<std::pair<long,long>, long>& p2)
  -> decltype(p1 < p2);
```
is silently accepted.

This bug is specific for C++17 compilation mode, because starting with C++20, the three-way comparison operator has a properly crafted return type declaration deducing it from argument types.  Still, this should be fixed since there are many software projects around which can't migrate to C++20 yet for various reasons.

The fix is very easy: instead of
```
bool operator<(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y)
```
it should be declared as
```
auto operator<(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y)
  -> decltype(__x.first < __y.first && __x.second < __y.second)
```
and the same for all other comparisons.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVcFu4zgM_RrlQiRw5LRJDj4kbbPYy14mcw5oibY1kCVDopv67xey3aYzk2JPiwGCGLIoku_pPRNjNLUjKsTDUTw8L7Dnxofi5VqTMz_-wmsw1l-XZ9-efbsovR4K31FA9kHkz-knn-D25gnQafDcUADl2w6Did59BETQVBlHGiofILIW-UHkhw5NAFSKOga-esBQGg4YBkg7ETBOGZyOqRy9kgNTATdkArTUlpSCAoFxUKFicJ7n8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