Aliasing bug in std::valarray
Bastian Pranzas
bastian@moduleworks.com
Fri Dec 6 17:23:00 GMT 2013
Hi,
std::valarray seems to show behaviour that I find at least unexpected
and think it might be a bug. Sample code:
#include <valarray>
#include <cstdio>
int main()
{
std::valarray<int> a {1, 1};
std::valarray<int> b {1, 1};
a -= b * a[0];
std::printf("%d\n", a[1]);
return 0;
}
The a[1] will still be 1 after the subtract, because a[0] will be set to
0 and then the 0 will be used for the second multiply. My expectation
from that code is that a[0] should be a fixed value throughout the whole
calculation.
Regards
--
Bastian Pranzas
ModuleWorks GmbH
More information about the Libstdc++
mailing list