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

    <tr>
        <th>Summary</th>
        <td>
            std::less doesn't work with unrelated pointers in constant expressions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

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

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

<pre>
    Is the following code valid?

```
#include <functional>

constexpr bool compare(int const* a, int const* b) {
 return std::less{}(a, b);
}

constexpr bool f() {
    int a = 1;
    int b = 2;
    return compare(&a, &b);
}

constexpr bool x = f();
```

https://godbolt.org/z/ddE168qnf

It fails with libstdc++ and libc++, but works with MSVC's STL.

I think it should be valid. Per https://eel.is/c++draft/comparisons#general-2, `std::less` is well-defined for pointer types and there's nothing that carves this out specifically from constant expressions in https://eel.is/c++draft/expr.const#5.

Related to this issue is the fact that this may have UB at runtime since `ptr1 < ptr2` is UB for unrelated pointers. I don't think Clang does anything with it, but apparently GCC does.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVFGP4yYQ_jX4ZbQWxokdP_hhk71UK7VS1ev1HcM4pkfAhfHupb--gvi662sr9aTIEQMz833ffCBjNBeH2LP9ke2fCrnQ5ENvtfHOYTF4feufI9CEMHpr_atxF1BeI7xIazSrz4w_Mf64fhu-_u5LURun7KIRWH0aF6fIeCctqz-8z1LeRcIvc4DBewvKX2cZkImDcQR5k4lHkEycYBMZmOiAtcd7FQhIS3AQSbP6kdWPFmNMu-0TE4ecnRJYvZ5P8f8GMTJx2JYHyN0lsPoJqr_LfI0POS428RXRGyEmmgyEieY7sHzJpVdEbznfaJ2_E9EcE31xZuJ88XrwlkofLkyc_2TirPWHqjn84cb3Sc8EozQ2wquhCawZImnFxJGJI0inU2RdZhEXglcfPq_Hf_r424mJNsLHX38sN1WBJuM-gyGIk1-shmE1TQk_Y4AtVERbmsjEee2kgxwpLbN2JnoXmagv6DBI-yCyiA3fzrrhYCK8orUPGkfjUMPoA8zeOMIAdJsxZkI0YRpHG8H5BPICNEkCJcMLJq-bCH4hiDMqMxolrb3BGPz1bj3pCNJwMEbjXQTj_ieXlFSu7q33G7F-QSsJNZC_tzcxLpjY5IsnFd0R5r2rvMEkXxA-HUEShMWRuSJE4xQmUWYKVbpvMFMQqyifjlmKxYW10SpKLOEZtHdMtLTO62Slu4D2WavbXZ48aUNfxy_n5GdH9gY_nE75bFnovtZd3ckC-6rpuqapeFcVUz_onZKdHg5D1yLn3U5odcBGSzXy-lCNhekFF3VVVRXnfLevSr7fHdq22teDVrxtke04XqWxpbUv12TmIsvTt4LzqrByQBvz-yXEe6uK9J6FPiU9DMslsh23JlJ8K0OGLPYbE2UydzmSye_M_ylbGvq_maFYgu2_uYSGpmUolb8ycU6t17-HOfjfUSVjZDrJMJnRXwEAAP__T1252g">