https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87641
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- Author: redi Date: Thu Oct 18 17:40:29 2018 New Revision: 265275 URL: https://gcc.gnu.org/viewcvs?rev=265275&root=gcc&view=rev Log: PR libstdc++/87641 correctly initialize accumulator in valarray::sum() Use the value of the first element as the initial value of the __valarray_sum accumulator. Value-initialization might not create the additive identity for the value type. PR libstdc++/87641 * include/bits/valarray_array.h (__valarray_sum): Use first element to initialize accumulator instead of value-initializing it. * testsuite/26_numerics/valarray/87641.cc: New test. Added: branches/gcc-8-branch/libstdc++-v3/testsuite/26_numerics/valarray/87641.cc Modified: branches/gcc-8-branch/libstdc++-v3/ChangeLog branches/gcc-8-branch/libstdc++-v3/include/bits/valarray_array.h