This code suffers from overflow because the type of intermediate results does not depend on the destination type:
vector< uint8_t > increments;
…
vector< uint32_t > increasing( increments.size() );
partial_sum( increments.begin(), increments.end(), increasing.begin() );
However, so does this (GCC 4.2):
partial_sum( increments.begin(), increments.end(), increasing.begin(),
plus< uint32_t >() );
Shouldn't plus< uint32_t >
promote its operands and avoid the overflow?
Edit: I'm too SO-addicted. After a short break, I sat back down and checked the implementation. It does this:
/* input_iterator::value_type */ __value = __binary_op(__value, *__first);
*++__result = __value;
I don't think that's compliant, so I'll check the latest version and maybe file a bug… and here we go: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42943