This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Aliasing bug in std::valarray


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


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