-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[C++23][Modules] imported function with auto return type causes lambda does not satisfy 'move_constructible' #130080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-modules Author: None (thbwd)
A.ixx:
```c++
module;
#include <vector> export module A; export auto f(const std::vector<int> &vec) { /void clang_bug_fix() {
Produces:
Even though the lambda is move constructible. The bug disappears when uncommenting the function clang_bug_fix. CMakeLists.txt: 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/issue-subscribers-clang-frontend Author: None (thbwd)
A.ixx:
```c++
module;
#include <vector> export module A; export auto f(const std::vector<int> &vec) { /void clang_bug_fix() {
Produces:
Even though the lambda is move constructible. The bug disappears when uncommenting the function clang_bug_fix. CMakeLists.txt: 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
) |
Is this reproducible when replacing the lambda with an equivalent hand-write function object? |
I didn't specifically test a separate function but just converting the lambda to a function pointer with the unary + makes the bug go away:
|
Ah, I think I misunderstood. I haven't tried writing an equivalent "functor" so far. |
I am not sure if this relates to #116087 Can you verify by adding an And also |
@ChuanqiXu9 Adding |
then could you try again with the newest clang in trunk? |
I tried reproducing it for both reduced and full BMI using clang trunk and the issue still remains. |
Just to make sure you meet the same problem, does it work for you if you add |
It also compiles successfully for me when adding The error message for both builds (full/reduced BMI) are also the same as the original, but I have attached the build commands with output below for good measure. Full BMI📦[nav@ubuntu-toolbox-24-10 test_130080]$ /home/nav/code/llvm/build/bin/clang++ -std=c++23 -stdlib=libc++ --precompile A.cppm -o A.pcm
📦[nav@ubuntu-toolbox-24-10 test_130080]$ /home/nav/code/llvm/build/bin/clang++ -std=c++23 -stdlib=libc++ -fmodule-file=A=A.pcm main.cpp
In module 'A' imported from main.cpp:3:
/usr/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 /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)]
187 | friend class transform_view<_View, _Fn>::__iterator;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/__ranges/transform_view.h:99:53: note: in instantiation of template class 'std::ranges::transform_view<std::ranges::ref_view<const std::vector<int>>, (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>::__iterator<false>' requested here
99 | _LIBCPP_HIDE_FROM_ABI constexpr __iterator<false> begin() { return __iterator<false>{*this, ranges::begin(__base_)}; }
| ^
main.cpp:6:18: note: in instantiation of member function 'std::ranges::transform_view<std::ranges::ref_view<const std::vector<int>>, (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>::begin' requested here
6 | for (int ptr : f(std::vector<int>(5))) {
| ^
/usr/include/c++/v1/__ranges/transform_view.h:70:30: note: because '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' does not satisfy 'move_constructible'
70 | template <input_range _View, move_constructible _Fn>
| ^
/usr/include/c++/v1/__concepts/constructible.h:39:62: note: because 'convertible_to<(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40), (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>' evaluated to false
39 | concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
| ^
/usr/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 /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' to '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)'
27 | concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
| ^
In module 'A' imported from main.cpp:3:
/usr/include/c++/v1/__ranges/transform_view.h:190:16: error: constraints not satisfied for class template 'transform_view' [with _View = std::ranges::ref_view<const std::vector<int>>, _Fn = (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)]
190 | friend class transform_view<_View, _Fn>::__sentinel;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/__ranges/transform_view.h:70:30: note: because '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' does not satisfy 'move_constructible'
70 | template <input_range _View, move_constructible _Fn>
| ^
/usr/include/c++/v1/__concepts/constructible.h:39:62: note: because 'convertible_to<(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40), (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>' evaluated to false
39 | concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
| ^
/usr/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 /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' to '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)'
27 | concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
| ^
2 errors generated. Reduced BMI📦[nav@ubuntu-toolbox-24-10 test_130080]$ /home/nav/code/llvm/build/bin/clang++ -std=c++23 -c -stdlib=libc++ -fmodules-reduced-bmi -fmodule-output=A.pcm A.cppm
📦[nav@ubuntu-toolbox-24-10 test_130080]$ /home/nav/code/llvm/build/bin/clang++ -std=c++23 -stdlib=libc++ -fmodule-file=A=A.pcm main.cpp
In module 'A' imported from main.cpp:3:
/usr/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 /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)]
187 | friend class transform_view<_View, _Fn>::__iterator;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/__ranges/transform_view.h:99:53: note: in instantiation of template class 'std::ranges::transform_view<std::ranges::ref_view<const std::vector<int>>, (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>::__iterator<false>' requested here
99 | _LIBCPP_HIDE_FROM_ABI constexpr __iterator<false> begin() { return __iterator<false>{*this, ranges::begin(__base_)}; }
| ^
main.cpp:6:18: note: in instantiation of member function 'std::ranges::transform_view<std::ranges::ref_view<const std::vector<int>>, (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>::begin' requested here
6 | for (int ptr : f(std::vector<int>(5))) {
| ^
/usr/include/c++/v1/__ranges/transform_view.h:70:30: note: because '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' does not satisfy 'move_constructible'
70 | template <input_range _View, move_constructible _Fn>
| ^
/usr/include/c++/v1/__concepts/constructible.h:39:62: note: because 'convertible_to<(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40), (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>' evaluated to false
39 | concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
| ^
/usr/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 /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' to '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)'
27 | concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
| ^
In module 'A' imported from main.cpp:3:
/usr/include/c++/v1/__ranges/transform_view.h:190:16: error: constraints not satisfied for class template 'transform_view' [with _View = std::ranges::ref_view<const std::vector<int>>, _Fn = (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)]
190 | friend class transform_view<_View, _Fn>::__sentinel;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/__ranges/transform_view.h:70:30: note: because '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' does not satisfy 'move_constructible'
70 | template <input_range _View, move_constructible _Fn>
| ^
/usr/include/c++/v1/__concepts/constructible.h:39:62: note: because 'convertible_to<(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40), (lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)>' evaluated to false
39 | concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
| ^
/usr/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 /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)' to '(lambda at /home/nav/code/llvm/debug-env/test_130080/A.cppm:9:40)'
27 | concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
| ^
2 errors generated. (+ same result when using the given CMake reproducer) |
A.ixx:
main.cpp:
Produces:
Even though the lambda is move constructible. The bug disappears when uncommenting the function clang_bug_fix.
CMakeLists.txt:
The text was updated successfully, but these errors were encountered: