<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64250>64250</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] static_cast in `ranges::__crend::__fn` is not required
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fznamznon
</td>
</tr>
</table>
<pre>
I discovered this while working on [D152003 ](https://reviews.llvm.org/D152003) which is a fix for https://github.com/llvm/llvm-project/issues/62863 . Per C++20 static cast to array of unknown bound `U[]` should yield the type `U[1]`.
Now [D152003 ](https://reviews.llvm.org/D152003) breaks libc++ tests, since the following static assertion fails with it:
```
#include <ranges>
using RangeCREndT = decltype(std::ranges::crend);
static_assert(!std::is_invocable_v<RangeCREndT, int (&)[]>);
source/llvm-project/build/bin/clang++ -std=c++20 t.cpp -stdlib=libc++ -c
t.cpp:4:15: error: static assertion failed due to requirement '!std::is_invocable_v<const std::ranges::__crend::__fn, int (&)[]>'
4 | static_assert(!std::is_invocable_v<RangeCREndT, int (&)[]>);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```
I noticed that that in libc++ there is a bunch of explicit static casts in ranges::__crend::__fn that endup transformed:
```
namespace ranges {
namespace __crend {
struct __fn {
template <class _Tp>
requires is_lvalue_reference_v<_Tp&&>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp&& __t) const
noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))))
-> decltype( ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)))
{ return ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)); }
template <class _Tp>
requires is_rvalue_reference_v<_Tp&&>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp&& __t) const
noexcept(noexcept(ranges::rend(static_cast<const _Tp&&>(__t))))
-> decltype( ranges::rend(static_cast<const _Tp&&>(__t)))
{ return ranges::rend(static_cast<const _Tp&&>(__t)); }
};
} // namespace __crend
```
Per discussion in [D152003 ](https://reviews.llvm.org/D152003) we agreed that it is a bug in libc++ so I'm filing this issue so it won't be lost/forgotten.
cc @mordante @philnik777
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVk1v4zYQ_TX0ZRBDJmXJPvjgjxgN0I_FYnsWKHJks6FJlaTsZA_97QUp2dHuZoMW21wqGDJtauZx3rwZDfdeHQziisw3ZL6b8C4crVvtPxt--mysmdRWPq8eQCov7BkdSghH5eFyVBrhYt2jMgewBsh8s5vNaZYxIPMdoYtjCK0nbE3ontC9w7PCi59qfT5NrTsQuh8eJ3QZvYkjKA8cGvUEjXXwpflBhWNXT4U9EbqPPoavu9bZP1AEQvfK-w49ofuCLgoGU_iADraEbgjd0Ax84EEJENwHCBa4c_wZbAOdeTT2YqC2nZFAiuz3nglSZOCPttMSnhXqGDZCeG7x-sysf2hKsh3J1r_ay49RUDvkjx60qkV_Zgjogyd0C14ZgQm_sVrbS2R8CId7jy4oa6DhSnu4qHAEFSJmOhYpsuHT_6RMGaE7iUDY1nFzQE_Y_bCZ7p2P7j_Gre3HeyM_AWE7kCh0DJ7QhQ8yumfrq3lcC4dGErokbNO76c9X9ecjdEHo7GaofKXM2Qpea6zOhG1HaDFeZQIkkyJ67LPB7sfeBwzbOYHfKqHulJbxWxlC90JzcxgovUtn2ImbKsJUtG36W6uasN2I_jvRo6RHCFvnhK1nc8LWgM5ZFxevJgElyA6jxhz-2SmHJ0zxlG9SIKzxAV7ltqp6docfjXmLo7I_NABADqTcwvsmAtIVccj8_q9_fvXWs55KOKBBxwPK6auqfQBjgxKp9fDQ35T5olSO6LDvH3VnxDEWNj61WgkVxpXvo92b3Pbe0ciuheC48Y11J5TfKyjDT-hbLnDwCqTcfL0zYMQtuBaH60SAhHczgICnVvOQSlNo7j1Un9pbdUaeB0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