| Issue |
60971
|
| Summary |
[Clang17] Ranges adaptor reverse with | no longer compiles when importing libc++ <ranges> header unit
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
kaimfrai
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs