This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: [BUG] valarray_copy, with mask_array, libstdc++-v3
- From: Ben Elliston <bje at redhat dot com>
- To: Luke Kenneth Casson Leighton <lkcl at samba-tng dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 4 Jul 2002 13:19:27 -0400 (EDT)
- Subject: Re: [BUG] valarray_copy, with mask_array, libstdc++-v3
- References: <20020703220138.GC10352@samba-tng.org>
>>>>> "Luke" == Luke Kenneth Casson Leighton <lkcl@samba-tng.org> writes:
Luke> valarray<bool> b(4);
Luke> b[0] = false;
Luke> b[1] = true;
Luke> b[2] = true;
Luke> b[0] = false;
Luke> valarray<int> i(4);
Luke> valarray<int> j;
Luke> i = 9;
Luke> j = i[b];
Luke> should create an array (j) of two items.
Luke> instead, it overwrites memory and corrupts things
Luke> because... well... here's a patch :)
In Section 22.4.2 of The C++ Programming Language (3rd edition):
``A valarray can be assigned to another of the same size. As one
would expect, v1 = v2 copies every element of v2 into its
corresponding position in v1. If valarrays have different sizes,
the result of assignment is undefined. Because valarray is designed
to be optimised for speed, it would be unwise to assume that
assigning with a valarray of the wrong size would cause an easily
comprehensible error (such as an exception) or other "reasonable"
behaviour.''
Ben