This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Aliasing bug in std::valarray
- From: Bastian Pranzas <bastian at moduleworks dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 06 Dec 2013 18:22:52 +0100
- Subject: Aliasing bug in std::valarray
- Authentication-results: sourceware.org; auth=none
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