From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 009E53857C45; Fri, 24 Feb 2023 19:31:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 009E53857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677267111; bh=F8QzdV9Lpf1BB3I2MmQ8dFnDtPIOTLhJCB5wP6RcJzM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LWU8V9+iDgVrSo/j+fa/Vx24AO5HXwl52CfFYoaCf/EfBYhLxST0bDeZsbUnf9Rjx Au0q4tR2QyfMJBqx2pM18PWA23NEL27HZeQnj6q2l9x5GdP3qF7t59WPj/TUnRQsrA VMnWxbti8bXR32/AUECsitGg+gdJhw6nX4ULO/xk= From: "dangelog at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108846] std::copy, std::copy_n and std::copy_backward on potentially overlapping subobjects Date: Fri, 24 Feb 2023 19:31:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: dangelog at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108846 --- Comment #12 from Giuseppe D'Angelo --- (In reply to Jonathan Wakely from comment #9) > (In reply to Giuseppe D'Angelo from comment #5) > > https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/= bits/ > > stl_algobase.h#L417-L437 > >=20 > > Is the extent of the fix just to add another branch to the if (_Num) ch= eck > > here? >=20 > Yes, I think that's the simplest place to fix it. >=20 > And we can even get rid of the static assertion, because the Num=3D=3D1 b= ranch > will require assignability now. >=20 > --- a/libstdc++-v3/include/bits/stl_algobase.h > +++ b/libstdc++-v3/include/bits/stl_algobase.h > @@ -737,16 +737,11 @@ _GLIBCXX_END_NAMESPACE_CONTAINER > static _Tp* > __copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __resul= t) > { > -#if __cplusplus >=3D 201103L > - using __assignable =3D __conditional_t<_IsMove, > - is_move_assignable<_Tp>, > - is_copy_assignable<_Tp>>; > - // trivial types can have deleted assignment > - static_assert( __assignable::value, "type must be assignable" ); > -#endif > const ptrdiff_t _Num =3D __last - __first; > - if (_Num) > + if (__builtin_expect(_Num > 1, true)) > __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Nu= m); > + else if (_Num =3D=3D 1) > + *__result =3D *__first; > return __result - _Num; > } > }; If this code path also takes care of std::move(b,e,o), then this doesn't so= und correct -- for _Num=3D=3D1 and _IsMove=3D=3Dtrue, then it should use a move= assignment (std::move(*__first)). But then that std::move doesn't actually work as __f= irst is a pointer to const...=