I came across this while gathering background for my post in c++std-lib-16112. I thgought I might as well let you know in case you think it's important enough to worry about (Size is only required to be convertible to an integral type which doesn't mean it needs to have the predecrement operator defined). The incorrect return type in this test case works around bug #25304.
$ cat t.cpp && g++ -c t.cpp #include <algorithm> struct Size { operator int() { return 0; } private: void operator=(Size&); }; template int* std::fill_n (int*, Size, const int&); template int* std::generate_n (int*, Size, int (*)()); int main () { } /usr/local/gcc-4.0.2/lib/gcc/sparc-sun-solaris2.9/4.0.2/../../../../include/c++/4.0.2/bits/stl_algo.h: In function '_OutputIterator std::generate_n(_OutputIterator, _Size, _Generator) [with _OutputIterator = int*, _Size = Size, _Generator = int (*)()]': t.cpp:10: instantiated from here /usr/local/gcc-4.0.2/lib/gcc/sparc-sun-solaris2.9/4.0.2/../../../../include/c++/4.0.2/bits/stl_algo.h:1003: error: no match for 'operator--' in '--__n' /usr/local/gcc-4.0.2/lib/gcc/sparc-sun-solaris2.9/4.0.2/../../../../include/c++/4.0.2/bits/stl_algobase.h: In static member function 'static _OutputIterator std::__fill_n<true>::fill_n(_OutputIterator, _Size, const _Tp&) [with _OutputIterator = int*, _Size = Size, _Tp = int]': /usr/local/gcc-4.0.2/lib/gcc/sparc-sun-solaris2.9/4.0.2/../../../../include/c++/4.0.2/bits/stl_algobase.h:642: instantiated from '_OutputIterator std::fill_n(_OutputIterator, _Size, const _Tp&) [with _OutputIterator = int*, _Size = Size, _Tp = int]' t.cpp:9: instantiated from here /usr/local/gcc-4.0.2/lib/gcc/sparc-sun-solaris2.9/4.0.2/../../../../include/c++/4.0.2/bits/stl_algobase.h:617: error: no match for 'operator--' in '--__n' -- Summary: fill_n, generate_n assume Size is modifiable Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sebor at roguewave dot com GCC build triplet: all GCC host triplet: all GCC target triplet: all http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25306