From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 66ED03858D37; Thu, 20 Apr 2023 17:10:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66ED03858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682010628; bh=XxKix8inuklXX4I9MXCmN8D8FVOQ4Z+cqw+CoFtLKYk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qx6SF7538EjGEQ5kh3o6kAM9TPU2h+6d0YgoXezpYHooH2H+Q/Ub2qu9JHrIdjfqh PawDgdehfTXMeztOGTAzsItW1+weHqs3QXuV3W+yLD+5RMZQOa2oajPPEdMY1K+KrX Kc6nvT5fPZ11hqD9nE1DFzghGBA/47reYUM6v2vI= 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, 20 Apr 2023 17:10:27 +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: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi 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 #24 from Jonathan Wakely --- (In reply to Arthur O'Dwyer from comment #23) > - There may be padding in the middle of an object, and I'm not confident > that the Standard actually forbids it from being used. Of course your > approach works fine on the Itanium ABI, and probably works everywhere that > actually exists. If you've got chapter+verse proving that it must work > *everywhere*, I'd appreciate seeing it, just for my own information. I don't care about everywhere, only GCC-like compilers on the targets they support. > - If GCC were ever to add a builtin for this notion, IMO the proper name > would be `__datasizeof(T)`. See > https://danakj.github.io/2023/01/15/trivially-relocatable.html#data-size I think it should have a __builtin_ prefix unless it directly implements a standard trait like __is_object. > - You can implement your library trait like this; see > https://quuxplusone.github.io/blog/2023/03/04/trivial-swap-prize-update/ > #step-1.-std-swap-can-t-assume-it >=20 > template > struct __libcpp_datasizeof { > struct _Up { > [[__no_unique_address__]] _Tp __t_; > char __c_; > }; > static const size_t value =3D __builtin_offsetof(_Up, __c_); > }; >=20 > Unfortunately it looks like GCC doesn't support > `__attribute__((__no_unique_address__))` in C++03 mode. (Neither does Cla= ng. > What is up with that!) Which is OK, because you can't have final types in C++03 either, so testing= it using inheritance is good enough for C++03. > Your suggested trait implementation is slightly wrong for `is_final` type= s: > you return 0 but really a final type _can_ have usable tail padding. See > https://godbolt.org/z/P6x459MEq Ah, I didn't think that padding would actually be used by an adjacent member subobject. But of course it can be for an empty class, where it consists of= a single byte of padding which can be reused by another member of a different type.=