This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [BUG] valarray_copy, with mask_array, libstdc++-v3


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]