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

    <tr>
        <th>Summary</th>
        <td>
            [libc++] reference type of the input range (and `_It`) isn't necessarily `const _ValueT&`
        </td>
    </tr>

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

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

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

<pre>
    While I did https://reviews.llvm.org/D142864 I add some `static_cast`s.
Casey Carter explained why they are needed (the explanation is about Microsoft STL but it is the same for libc++):

>We get here from one of two places: the `initializer_list` overload of `operator()` defined on 10084, or the `range` overload defined on 10096. If it's the former, we know that the value type of the range `_Vty` is `copyable` and the reference type is `const _Vty&` so `*_Result.first` implicitly converts to `_Vty` - we don't need the static_cast.
>
>In the latter case, `indirectly_copyable_storable<_It, _Vty*>` (https://eel.is/c++draft/alg.req.ind.copy#2) also requires that `_Vty` is `copyable`, but the reference type of the input range (and `_It`) isn't necessarily `const _Vty&` so we don't have the same guarantee of implicit convertibility. In fact there's no requirement on that algorithm that lets us implicitly convert the result of an iterator dereference to `_Vty`. There is a requirement that `constructible_from<_Vty, iter_reference_t<_It>>` holds, however, so we can perform the conversion explicitly with `static_cast`.

An example of affected code: https://github.com/llvm/llvm-project/blob/4afb1ee7bc0e3674238da2d3668f8d8b80596c62/libcxx/include/__algorithm/ranges_minmax.h#L80

philnik wrote that we should check all algorithms for the issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VV-P4jYQ_zTmZXSRcUIIDzzs7R4S0vWlPfUekWNPiLuOnbMnsPTTV3aAZdVrpT5UWi2EjGfm92fGMkZzdIhbtvrMVi8LOVHvw7aLbcU5X7ReX7bfe2MR9qCNhp5ojKx8YmLHxC7gyeA5FtaehsKHIxO7l2UlmrqCPUitIfoBgdU8kiSjDkpGSk8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