<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/130080>130080</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++23][Modules] imported function with auto return type causes lambda does not satisfy 'move_constructible'
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thbwd
</td>
</tr>
</table>
<pre>
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
)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWd9v2zgS_muYl4EFibIt-cEP8g_hgq23QZNd9J4EWhpbvEqkjqQc5-X-9gMpyZGbZC-9XXT3Di2ExqHI4cz3zXzD0ExrfhSISzJbkdnmhrWmlGppyv1jcbOXxdMy8fj5TMKE-AmZ-92TE7qyj5_UsmgrJKH9bB8acpFXbYFAwvUJcyMVCbcv3igmjqj7N36C50YqA50xSC7m-nHWGgkHQuNcCm1Am8L6EyaD_TUXhoRbIHR-wpzQBZDIWgAAUGhaJeCEOZBoPVrL8VF3H41iQh-kqgmNOxgIjbkwcL42NTJ3BkJXEHSO2nESbQhd9I5HmwGNlNDkJHkBecXEMdu3x-zAz3afK8sHqYDQ2MV5BhImLtq34uyW989lR-q2G5Fk2WFceHnTvEnfb_DlJ7x26D_TYTGxJt_y375vjHpPALNLBIOZHrULdqMwiJ_cKVm0Oeo-kq_e01Q2htC0lDXuFT4Smq6xqpgiNK2qU01oGiy8wIuygNB0byNIHSMdEDA5wsQ5uzmKthujIUyYyktgqp5PYcL1k1ZSGiA0TZqm4jkzXApNaPo5lwV6rGnstlIYFMYOb_CElWzQO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