Issue 89898
Summary Ranges pipe syntax broken after commit #c1086532d4d5 when using std module.
Labels new issue
Assignees
Reporter stripe2933
    The following code

```cpp
#include <print>
#include <ranges>

int main(){
    using namespace std::string_view_literals;
    std::println("{}", "abcde"sv | std::views::transform([](char c) { return c - 'a'; }));
 
}
```

works correctly ([godbolt link](https://godbolt.org/z/T4vYssK8z)) in Clang trunk. However, when changing the header inclusion to `import std;`, then the code will emit error:

```
main.cpp:5:34: error: invalid operands to binary _expression_ ('basic_string_view<char>' and '__range_adaptor_closure_t<__bind_back_t<__fn, tuple<(lambda at main.cpp:5:58)>>>' (aka 'std::__1::ranges::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__transform::__fn, std::__1::tuple<(lambda at main.cpp:5:58)>>>'))
    5 | std::println("{}", "abcde"sv | std::views::transform([](char c) { return c - 'a'; }));
      |                        ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm-project/build/include/c++/v1/cstddef:73:45: note: candidate function not viable: no known conversion from 'basic_string_view<char>' to 'byte' for 1st argument
   73 | _LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {
      |                                             ^ ~~~~~~~~~~
llvm-project/build/include/c++/v1/__charconv/chars_format.h:34:53: note: candidate function not viable: no known conversion from 'basic_string_view<char>' to 'chars_format' for 1st argument
   34 | inline _LIBCPP_HIDE_FROM_ABI constexpr chars_format operator|(chars_format __x, chars_format __y) {
      | ^ ~~~~~~~~~~~~~~~~
llvm-project/build/include/c++/v1/future:433:55: note: candidate function not viable: no known conversion from 'basic_string_view<char>' to 'launch' for 1st argument
  433 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR launch operator|(launch __x, launch __y) {
      |                                                       ^ ~~~~~~~~~~
llvm-project/build/include/c++/v1/bitset:929:1: note: candidate template ignored: could not match 'bitset' against 'basic_string_view'
  929 | operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
      | ^
llvm-project/build/include/c++/v1/valarray:2858:1: note: candidate template ignored: requirement '__is_val_expr<std::__1::basic_string_view<char, std::__1::char_traits<char>>>::value' was not satisfied [with _Expr1 = basic_string_view<char>, _Expr2 = __range_adaptor_closure_t<__bind_back_t<__fn, tuple<(lambda at main.cpp:5:58)>>>]
 2858 | operator|(const _Expr1& __x, const _Expr2& __y) {
      | ^
llvm-project/build/include/c++/v1/valarray:2867:5: note: candidate template ignored: requirement '__is_val_expr<std::__1::basic_string_view<char, std::__1::char_traits<char>>>::value' was not satisfied [with _Expr = basic_string_view<char>]
 2867 |     operator|(const _Expr& __x, const typename _Expr::value_type& __y) {
      | ^
llvm-project/build/include/c++/v1/valarray:2876:5: note: candidate template ignored: requirement '__is_val_expr<std::__1::ranges::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__transform::__fn, std::__1::tuple<(lambda at main.cpp:5:58)>>>>::value' was not satisfied [with _Expr = __range_adaptor_closure_t<__bind_back_t<__fn, tuple<(lambda at main.cpp:5:58)>>>]
 2876 |     operator|(const typename _Expr::value_type& __x, const _Expr& __y) {
      |     ^
1 error generated.
```

Compiler: Clang 18.1.4, Libc++: trunk.

I followed the standard library module instruction documented in [libc++ document](https://libcxx.llvm.org/Modules.html#using-in-external-projects).

I noticed that the commits before `c1086532d4d5`, which corresponds to the PR #89148 does not print this error. It seems that the PR is problem.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to