<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64702>64702</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
some error in operator= in valarray
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hutoushayu
</td>
</tr>
</table>
<pre>
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 ?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV8ty6zYPfhp6gzkeCbJseeGFL_FMFv_q76bdaGgJspgjUSpJ5cR9-g4pybrEOU3arqoFExAE8OFGwlxrcZVEOxYeWHha8MbkldrljakanfNbs7hU6W33LMHkBAnXxJ7O7HBk0VHIVChKTMyV4jcAQ2XtuxUhUcQNQaaqEjQvCV55wZW63YUB2BOyyGPbYyvHglMry4JDzzoB_KCigCsZIKUqBYp0Uxj2FFh-hMw7MW__bBhutAPobAkJUHL9vQM22LzqQiQ03364OXVuZrBb1x7DQMikaFICFhxFpY0iXrLgqTsxYbch4LeB3R9KKROS4H-__v_5tyeG0SvDLUw_hpEWf1CVdWyG5xEdHjwWntz2dqy70UJeQfKSdM0TAm1SG97RiddKpO1_hrRhGA0aNt1BACENCFk3pi0Slyu2OYDH8Ai-XdAugV1Wdgntsga2Od3NQWt8z4L9EIijkIYFTwCZKApKGUatGTwOweh2nGuDsloJaTKHFzvhYA8Mw9QKf-lveJQMrQOdnj6YA-3PaJzRwYxezehwRq-7ZE1TAWAzGhv48BMypTfS_iwN_jT4n4l7a8mFfqrddxHvzEzT0G_OMvFJ0PgI9Khs_gloHPDhI9A4A90bSSqpzWBq1vNDdfZ3m8V-T2IXrnCM-msK8YFCHCv8TOdMv6oxNoMO7scN03vzFw1zbwyn9d4WHeVPKJxQwazAv-gCdi7gz13Ar7mAExdw4gJOXMAHLvQgGJ4ZniHJKfkOOSnqGQ-esYngGH2Sc3l1V9Yd4d8LFpf630-3VXoPVUv4YwLHxPtU_7eu5s1p8li71b6HJRfyg-dy9JKO1ay995qeweRCfm-Hqyp1s0shLsnbG8NzNzswPPd1ACA0_FCVvC47JBlc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