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

    <tr>
        <th>Summary</th>
        <td>
            [Clang17] Ranges adaptor reverse with | no longer compiles when importing libc++ <ranges> header unit
        </td>
    </tr>

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

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

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

<pre>
    A recent update in Clang17 made the following code no longer compile:

```
// clang++-17 -std=c++20 -stdlib=libc++ --precompile -xc++-system-header ranges -o ranges.pcm
// clang++-17 -std=c++20 -stdlib=libc++ main.cpp -fmodule-file=ranges.pcm
import <ranges>;

int main()
{
        int arr[]{ 0, 1, 2, 3, 4, 5 };
        int product1 = 0;
        for (auto i : arr | std::views::reverse)
        {
                product1 *= i;
        }
        int product2 = 0;
        for (auto i : std::views::reverse(arr))
        {
                product2 *= i;
        }
        return product1 + product2;
}
```
It errors out with the following message:
```
main.cpp:9:20: error: invalid operands to binary expression ('int[6]' and 'const __reverse::__fn')
        for (auto i : arr | std::views::reverse)
                      ~~~ ^ ~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm-17/bin/../include/c++/v1/cstddef:74:39: note: candidate function not viable: no known conversion from 'int[6]' to 'byte' for 1st argument
_LIBCPP_HIDE_FROM_ABI constexpr byte  operator| (byte  __lhs, byte __rhs) noexcept
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:58:37: note: candidate template ignored: constraints not satisfied [with _View = int (&)[6], _Closure = const __reverse::__fn &]
    friend constexpr decltype(auto) operator|(_View&& __view, _Closure&& __closure)
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:55:18: note: because 'same_as<std::ranges::views::__split_view::__fn, remove_cvref_t<const __fn &> >' evaluated to false
        requires same_as<_Tp, remove_cvref_t<_Closure>> &&
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__concepts/same_as.h:29:19: note: because '__same_as_impl<std::ranges::views::__split_view::__fn, std::ranges::views::__reverse::__fn>' evaluated to false
concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__concepts/same_as.h:26:26: note: because '_IsSame<__fn, __fn>::value' evaluated to false
concept __same_as_impl = _IsSame<_Tp, _Up>::value;
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:67:27: note: candidate template ignored: constraints not satisfied [with _Closure = int (&)[6], _OtherClosure = const __reverse::__fn &]
    friend constexpr auto operator|(_Closure&& __c1, _OtherClosure&& __c2)
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:62:15: note: because 'int (&)[6]' does not satisfy '_RangeAdaptorClosure'
 template <_RangeAdaptorClosure _Closure, _RangeAdaptorClosure _OtherClosure>
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:50:32: note: because 'derived_from<remove_cvref_t<int (&)[6]>, __range_adaptor_closure<remove_cvref_t<int (&)[6]> > >' evaluated to false
concept _RangeAdaptorClosure = derived_from<remove_cvref_t<_Tp>, __range_adaptor_closure<remove_cvref_t<_Tp>>>;
 ^
/usr/lib/llvm-17/bin/../include/c++/v1/__concepts/derived_from.h:28:3: note: because 'is_base_of_v<std::__range_adaptor_closure<int[6]>, int[6]>' evaluated to false
  is_base_of_v<_Bp, _Dp> &&
  ^
1 error generated.
```
Note that only the | syntax causes a problem. The call syntax does not.
The issue is not present when using an `#include <ranges>` instead of the `import <ranges>;`. It is also not present in Clang16 or when using libstdc++. It was also not present in Clang17 a few days ago.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8mFtv47oRgH8N_TKwIVOxZT34wZcYDdD2HGz39JWgpJHNHolUScpev-xvL4aSbSVxsik2Z41AkXibmY8zw4t0Tu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