| Issue |
64702
|
| Summary |
some error in operator= in valarray
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
hutoushayu
|
In the case,indirect_array temp1 temp2 create from same valarry, “temp1 = temp2;” well get error result。
It's the same in mask_array , gslice_array ,slice_array ,indirect_array。
`#include <iostream>
#include <valarray>
#define MYSIZE(v) (sizeof(v)/sizeof(v[0]))
using namespace std;
void
test()
{
int input[] = { 0, 1, 2, 3, 4, 5, 6 };
std::valarray<int> filled(input, MYSIZE(input));
printf("filled: %d, %d, %d, %d, %d, %d, %d\n",filled[0],filled[1],filled[2],filled[3],filled[4],filled[5],filled[6]);
size_t indexes1[] = { 1, 3, 4, 6 };
std::valarray<size_t> index1(indexes1, MYSIZE(indexes1));
size_t indexes2[] = { 1, 2, 3, 4 };
std::valarray<size_t> index2(indexes2, MYSIZE(indexes2));
const std::indirect_array<int> temp1 = filled[index1];
const std::indirect_array<int> temp2 = filled[index2];
std::valarray<int> out1(temp1);
printf("temp1 : %d, %d, %d, %d\n",out1[0],out1[1],out1[2],out1[3]);
std::valarray<int> out2(temp2);
printf("temp2 : %d, %d, %d, %d\n",out2[0],out2[1],out2[2],out2[3]);
// check here
temp1 = temp2;
printf("changed:\n");
std::valarray<int> ans(temp1);
printf("temp1 : %d, %d, %d, %d\n",ans[0],ans[1],ans[2],ans[3]);
printf("filled: %d, %d, %d, %d, %d, %d, %d\n",filled[0],filled[1],filled[2],filled[3],filled[4],filled[5],filled[6]);
}
int main()
{
test();
}`
I think the code in libcxx/include/valarray is wrong.
if both sides of the equal sign create from same valarry, __vp_ and __s well operation memory at same time.
`template <class _Tp>
inline
const indirect_array<_Tp>&
indirect_array<_Tp>::operator=(const indirect_array& __ia) const
{
typedef const size_t* _Ip;
const value_type* __s = __ia.__vp_;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
__i != __e; ++__i, ++__j)
__vp_[*__i] = __s[*__j];
return *this;
}`
well it be fixed ?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs