Undefined behaviour sanitizer error:
runtime error: implicit conversion from type 'int' of value -2147031364 (32-bit, signed) to type 'uint64_t' (aka 'unsigned long') changed the value to 18446744071562520252 (64-bit, unsigned)
The prototype of std::accumulate is:
template< class InputIt, class T, class BinaryOperation >
T accumulate( InputIt first, InputIt last, T init,
BinaryOperation op );
and the type T is deduced from the parameter init which is 0 aka signed int. The op lambda can return a value larger than 2147483647 which is implicitly converted back to the init type as a negative value. The next application of op is given a negative signed int as the sum which is implicitly converted to a very large 64bit number.
Undefined behaviour sanitizer error:
runtime error: implicit conversion from type 'int' of value -2147031364 (32-bit, signed) to type 'uint64_t' (aka 'unsigned long') changed the value to 18446744071562520252 (64-bit, unsigned)
The prototype of
std::accumulate
is:and the type T is deduced from the parameter
init
which is 0 aka signed int. Theop
lambda can return a value larger than 2147483647 which is implicitly converted back to theinit
type as a negative value. The next application ofop
is given a negative signed int as thesum
which is implicitly converted to a very large 64bit number.