PR libstdc++/87641 correctly initialize accumulator in valarray::sum()
commitce6b9c7814e545c9081387bb515fde4767f380ef
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Oct 2018 15:38:50 +0000 (18 15:38 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Oct 2018 15:38:50 +0000 (18 15:38 +0000)
treeceb55f655207d0eb8205ce2feba2e21d59e1cd64
parent68a7311760a43426daf73beddb98bc930439f19d
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.

Make a similar change to __valarray_product even though it's only ever
used internally with a value_type of size_t.

PR libstdc++/87641
* include/bits/valarray_array.h (__valarray_sum): Use first element
to initialize accumulator instead of value-initializing it.
(__valarray_product<_Tp>): Move to ...
* src/c++98/valarray.cc (__valarray_product<_Tp>): Here. Use first
element to initialize accumulator.
(__valarray_product(const valarray<size_t>&)): Remove const_cast made
unnecessary by LWG 389.
* testsuite/26_numerics/valarray/87641.cc: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265270 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/valarray_array.h
libstdc++-v3/src/c++98/valarray.cc
libstdc++-v3/testsuite/26_numerics/valarray/87641.cc [new file with mode: 0644]