Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] reference type of the input range (and _It) isn't necessarily const _ValueT& #60680

Open
fsb4000 opened this issue Feb 11, 2023 · 0 comments
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`

Comments

@fsb4000
Copy link
Member

fsb4000 commented Feb 11, 2023

While I did https://reviews.llvm.org/D142864 I add some static_casts.
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:

return {*__result.first, *__result.second};

philnik wrote that we should check all algorithms for the issue.

@fsb4000 fsb4000 added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 11, 2023
@philnik777 philnik777 added the ranges Issues related to `<ranges>` label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`
Projects
None yet
Development

No branches or pull requests

2 participants