From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8C1593858C00; Thu, 23 Feb 2023 17:26:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C1593858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677173160; bh=s8+ghKf+sKcHpWgNZV5fZ/gn6J90WoK1SFv8oE7Q1OQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ll5Tz7/f/2itQ90zS+CvgqzEk6Z6VsbcQ49A9ScJrhCAKORx+zjLKAC0EbbsAk6SZ hxj/ErpnWhoSjCrW08WN/TXj1he2NJlnxv6oTyCZIPvbQ6wsT5eeUV/y1Zzn0FOhzf UkerPe4PB7hH4xgPUiFLa50XHX7GhJqYOAn6x3f0= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108846] std::copy, std::copy_n and std::copy_backward on potentially overlapping subobjects Date: Thu, 23 Feb 2023 17:25:57 +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: redi at gcc dot gnu.org 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 #9 from Jonathan Wakely --- (In reply to Giuseppe D'Angelo from comment #5) > https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bi= ts/ > stl_algobase.h#L417-L437 >=20 > Is the extent of the fix just to add another branch to the if (_Num) check > here? Yes, I think that's the simplest place to fix it. And we can even get rid of the static assertion, because the Num=3D=3D1 bra= nch will require assignability now. --- 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* __result) { -#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) * _Num); + else if (_Num =3D=3D 1) + *__result =3D *__first; return __result - _Num; } };=