Issue 130080
Summary [C++23][Modules] imported function with auto return type causes lambda does not satisfy 'move_constructible'
Labels
Assignees
Reporter thbwd
    A.ixx:
```c++
module;

#include <vector>
#include <ranges>

export module A;

export auto f(const std::vector<int> &vec) {
    return vec | std::views::transform([](int x) {
        return x + 1;
    });
}

/*void clang_bug_fix() {
    for (auto x : f(std::vector<int>()));
}*/
```
main.cpp:
```c++
#include <vector>

import A;

int main() {
    for (int ptr : f(std::vector<int>(5))) {
 }
}

```

Produces:

```
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/clang++ -g -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -fcolor-diagnostics -MD -MT CMakeFiles/test.dir/main.cpp.o -MF CMakeFiles/test.dir/main.cpp.o.d @CMakeFiles/test.dir/main.cpp.o.modmap -o CMakeFiles/test.dir/main.cpp.o -c path/main.cpp
In module 'A' imported from path/main.cpp:3:
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__ranges/transform_view.h:184:16: error: constraints not satisfied for class template 'transform_view' [with _View = std::ranges::ref_view<const std::vector<int>>, _Fn = (lambda at path/A.ixx:9:40)]
  184 |   friend class transform_view<_View, _Fn>::__iterator;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__ranges/transform_view.h:97:53: note: in instantiation of template class 'std::ranges::transform_view<std::ranges::ref_view<const std::vector<int>>, (lambda at path/A.ixx:9:40)>::__iterator<false>' requested here
   97 | _LIBCPP_HIDE_FROM_ABI constexpr __iterator<false> begin() { return __iterator<false>{*this, ranges::begin(__base_)}; }
      | ^
path/main.cpp:6:18: note: in instantiation of member function 'std::ranges::transform_view<std::ranges::ref_view<const std::vector<int>>, (lambda at path/A.ixx:9:40)>::begin' requested here
    6 |     for (int ptr : f(std::vector<int>(5))) {
      | ^
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__ranges/transform_view.h:68:30: note: because '(lambda at path/A.ixx:9:40)' does not satisfy 'move_constructible'
   68 | template <input_range _View, move_constructible _Fn>
      | ^
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__concepts/constructible.h:39:62: note: because 'convertible_to<(lambda at path/A.ixx:9:40), (lambda at path/A.ixx:9:40)>' evaluated to false
   39 | concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
      | ^
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__concepts/convertible_to.h:27:69: note: because 'static_cast<_To>(std::declval<_From>())' would be invalid: no matching conversion for static_cast from '(lambda at path/A.ixx:9:40)' to '(lambda at path/A.ixx:9:40)'
   27 | concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
      | ^
In module 'A' imported from path/main.cpp:3:
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__ranges/transform_view.h:187:16: error: constraints not satisfied for class template 'transform_view' [with _View = std::ranges::ref_view<const std::vector<int>>, _Fn = (lambda at path/A.ixx:9:40)]
  187 |   friend class transform_view<_View, _Fn>::__sentinel;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__ranges/transform_view.h:68:30: note: because '(lambda at path/A.ixx:9:40)' does not satisfy 'move_constructible'
   68 | template <input_range _View, move_constructible _Fn>
      | ^
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__concepts/constructible.h:39:62: note: because 'convertible_to<(lambda at path/A.ixx:9:40), (lambda at path/A.ixx:9:40)>' evaluated to false
   39 | concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
      | ^
/opt/homebrew/Cellar/llvm/19.1.7_1/bin/../include/c++/v1/__concepts/convertible_to.h:27:69: note: because 'static_cast<_To>(std::declval<_From>())' would be invalid: no matching conversion for static_cast from '(lambda at path/A.ixx:9:40)' to '(lambda at path/A.ixx:9:40)'
   27 | concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
      | ^
2 errors generated.
```

Even though the lambda is move constructible. The bug disappears when uncommenting the function clang_bug_fix.


CMakeLists.txt:
```cmake
cmake_minimum_required(VERSION 3.30)
project(test)

set(CMAKE_CXX_STANDARD 23)

add_executable(test main.cpp)

target_sources(test
        PUBLIC
        FILE_SET all_my_modules TYPE CXX_MODULES FILES
        A.ixx
)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to