https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91748
Bug ID: 91748 Summary: doesn't compile std::for_each_n for random access iterator range Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: faithandbrave at gmail dot com Target Milestone: --- #include <algorithm> int main() { int ar[] = {1, 2, 3}; std::for_each_n(ar, 3, [](int) {}); } doesn't compile the code. compilation error is follow: In file included from /opt/wandbox/gcc-head/include/c++/10.0.0/algorithm:62, from prog.cc:1: /opt/wandbox/gcc-head/include/c++/10.0.0/bits/stl_algo.h: In instantiation of '_InputIterator std::for_each_n(_InputIterator, _Size, _Function) [with _InputIterator = int*; _Size = int; _Function = main()::<lambda(int)>]': prog.cc:5:36: required from here /opt/wandbox/gcc-head/include/c++/10.0.0/bits/stl_algo.h:3996:22: error: cannot convert 'main()::<lambda(int)>' to 'int*' in return 3996 | return std::for_each(__first, __first + __n2, __f); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | main()::<lambda(int)> It seems mistake return type. The function should returns iterator, but the function returns function object. https://github.com/gcc-mirror/gcc/blob/b8f684bc811e410d9cd82de83e8e6d4cc15dca8c/libstdc%2B%2B-v3/include/bits/stl_algo.h#L3996