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

    <tr>
        <th>Summary</th>
        <td>
            __duration_lt overflows with std::chrono::milliseconds::max()
        </td>
    </tr>

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

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

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

<pre>
    The following line should compile with libc++, but doesn't:

```c++
static_assert(std::chrono::nanoseconds{ 42 } <= std::chrono::milliseconds::max());
```

The issue is that `__duration_lt` will at some point multiply `std::chrono::milliseconds::max()` to 1,000,000 to get a nanosecond representation, and will overflow:

```
duration.h(97, 59): Value 9223372036854775807000000 is outside the range of representable values of type 'long long'
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVU9tu5CAM_RryYu2IgVwf8jDtqF-w2tcRCZ6EioEISC9_vybRbLur7kMjixgb7OOTk8Hr9_7njHD11vpX4yawxiHE2a9Ww-hvi7EIrybNlBhGJh42e4RhTaA9RsdEk5g8MX5m_L7WfLf7-S0ak0pmvKgYMSQm2ph0vidP4xy887vvlPMRR-90ZM0DlAJYcwYmH5k8w5c3bsZac7-yR9QblWeiyyYf_sH0GWie3MS45hXSrBLQgctFr4GgenexifY0vbVAuehvCIs3LsFttcks9j2f_zYqKpk8HIlFzvm-5sCECRR8EAABl4ARXdrAZNIVRTc0_gXDlT7Y_4jft_c5DjN17ppcodpJOcEvZWnsTggpG8Fl3VZl01Qtb_j2ZEL8mqLRSMQgBOUmBH_9BGogYbzkKjHH0_uCQFqwPmuIFvK_BFVgf6xrWdfUTRS6l7qTnSqSSRb7v7j_M2XcBfhdoos12H5OadkS4olsojrrcCBd08bal_vrxxL8M44ky6dND5GcqmllV8x91epG13jl-toN3XGoVCXKUbRYD7oc9VBYNaCNPatI68Lh6y4p8ll1LkwvuBC8E5x3leTigFVZo5YlV4rrVh1ZyfGmjD1kHAcfpiL0G6RhnSIlaboUP5L0-5jJIW7tqL5a0-xD_xb8OGOxde435L8BT0kuDg">