[libcxx-commits] [libcxx] [libcxx] Optimize std::generate for segmented iterators (PR #163006)
Connector Switch via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 14 11:29:45 PDT 2025
c8ef wrote:
> This usually indicates that your code doesn't work in C++14 mode. You should try to run lit with e.g. `--param=std=c++03` and see whether that fails.
```
# .---command stderr------------
# | In file included from C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:
14:
# | In file included from C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/algorithm:1861:
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/for_each.h:34:5: error: no matching function
for call to '__invoke'
# | 34 | std::__invoke(__f, std::__invoke(__proj, *__first));
# | | ^~~~~~~~~~~~~
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/for_each.h:57:8: note: in instantiation of f
unction template specialization 'std::__for_each<LifetimeIterator, LifetimeIterator, (lambda at C://llvm-project/build/libcx
x/test-suite-install/include/c++/v1/__algorithm/generate.h:24:34), std::__identity>' requested here
# | 57 | std::__for_each(__first, __last, __f, __proj);
# | | ^
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/generate.h:24:8: note: in instantiation of f
unction template specialization 'std::for_each<LifetimeIterator, (lambda at C://llvm-project/build/libcxx/test-suite-install
/include/c++/v1/__algorithm/generate.h:24:34)>' requested here
# | 24 | std::for_each(__first, __last, [&](auto& __element) { __element = __gen(); });
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:710:47: note: in insta
ntiation of function template specialization 'std::generate<LifetimeIterator, (lambda at C://llvm-project/libcxx/test/std/al
gorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp:651:14)>' requested here
# | 710 | test(simple_in, [&](I b, I e) { (void) std::generate(b, e, gen); });
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:710:33: note: while su
bstituting into a lambda expression here
# | 710 | test(simple_in, [&](I b, I e) { (void) std::generate(b, e, gen); });
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:763:3: note: in instan
tiation of function template specialization 'test<LifetimeIterator>' requested here
# | 763 | test<LifetimeIterator>();
# | | ^
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__type_traits/invoke.h:88:69: note: candidate template i
gnored: substitution failure [with _Args = <(lambda at C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__alg
orithm/generate.h:24:34) &, LifetimeIterator::Reference>]: no type named 'type' in 'std::__invoke_result_impl<void, (lambda at C:/Users/Mario/Doc
uments/llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/generate.h:24:34) &, LifetimeIterator::Reference>'
# | 85 | using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Args...>::type;
# | | ~~~~~
# | 86 |
# | 87 | template <class... _Args>
# | 88 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __invoke_result_t<_Args...> __invoke(_Args&&... __args)
# | | ^
# | In file included from C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:
14:
# | In file included from C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/algorithm:1861:
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/for_each.h:34:5: error: no matching function
for call to '__invoke'
# | 34 | std::__invoke(__f, std::__invoke(__proj, *__first));
# | | ^~~~~~~~~~~~~
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/for_each.h:57:8: note: in instantiation of f
unction template specialization 'std::__for_each<ConstexprIterator, ConstexprIterator, (lambda at C://llvm-project/build/lib
cxx/test-suite-install/include/c++/v1/__algorithm/generate.h:24:34), std::__identity>' requested here
# | 57 | std::__for_each(__first, __last, __f, __proj);
# | | ^
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/generate.h:24:8: note: in instantiation of f
unction template specialization 'std::for_each<ConstexprIterator, (lambda at C://llvm-project/build/libcxx/test-suite-instal
l/include/c++/v1/__algorithm/generate.h:24:34)>' requested here
# | 24 | std::for_each(__first, __last, [&](auto& __element) { __element = __gen(); });
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:710:47: note: in insta
ntiation of function template specialization 'std::generate<ConstexprIterator, (lambda at C://llvm-project/libcxx/test/std/a
lgorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp:651:14)>' requested here
# | 710 | test(simple_in, [&](I b, I e) { (void) std::generate(b, e, gen); });
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:710:33: note: while su
bstituting into a lambda expression here
# | 710 | test(simple_in, [&](I b, I e) { (void) std::generate(b, e, gen); });
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:765:17: note: in insta
ntiation of function template specialization 'test<ConstexprIterator>' requested here
# | 765 | static_assert(test<ConstexprIterator>());
# | | ^
# | C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__type_traits/invoke.h:88:69: note: candidate template i
gnored: substitution failure [with _Args = <(lambda at C://llvm-project/build/libcxx/test-suite-install/include/c++/v1/__alg
orithm/generate.h:24:34) &, ConstexprIterator::Reference>]: no type named 'type' in 'std::__invoke_result_impl<void, (lambda at C:/Users/Mario/Do
cuments/llvm-project/build/libcxx/test-suite-install/include/c++/v1/__algorithm/generate.h:24:34) &, ConstexprIterator::Reference>'
# | 85 | using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Args...>::type;
# | | ~~~~~
# | 86 |
# | 87 | template <class... _Args>
# | 88 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __invoke_result_t<_Args...> __invoke(_Args&&... __args)
# | | ^
# | C:\\llvm-project\libcxx\test\std\algorithms\robust_against_proxy_iterators_lifetime_bugs.pass.cpp:765:17: error: static
assertion expression is not an integral constant expression
# | 765 | static_assert(test<ConstexprIterator>());
# | | ^~~~~~~~~~~~~~~~~~~~~~~~~
# | 3 errors generated.
# `-----------------------------
# error: command failed with exit status: 1
```
I still haven't figured out why the regex check failed, but one of the test error message is above. I suspect it relates to std::__invoke. Is it possible to revert to the original version without forwarding to std::for_each?
https://github.com/llvm/llvm-project/pull/163006
More information about the libcxx-commits
mailing list