https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99117
--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So perhaps (totally untested): --- libstdc++-v3/include/std/valarray.jj 2021-01-04 10:26:02.366967342 +0100 +++ libstdc++-v3/include/std/valarray 2021-02-23 15:16:22.402688841 +0100 @@ -838,7 +838,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // 630. arrays of valarray. if (_M_size == __e.size()) - std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); + std::__valarray_copy(__e, _M_size, _M_data); else { if (_M_data) --- libstdc++-v3/include/bits/valarray_array.tcc.jj 2021-01-04 10:26:03.768951467 +0100 +++ libstdc++-v3/include/bits/valarray_array.tcc 2021-02-23 15:15:29.273282041 +0100 @@ -146,6 +146,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION *__p = __e[__i]; } + // Copy n consecutive elements of e into consecutive elements of p. + // I.e. p[i] = e[i]. p can alias what e uses. + template<typename _Tp, class _Dom> + void + __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Tp* __p) + { + for (size_t __i = 0; __i < __n; ++__i, ++__p) + *__p = __e[__i]; + } + // Copy n consecutive elements of e into elements of a using stride // s. I.e., a[0] = e[0], a[s] = e[1], a[2*s] = e[2]. template<typename _Tp, class _Dom>