public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "arthur.j.odwyer at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/68350] std::uninitialized_copy overly restrictive for trivially_copyable types
Date: Thu, 24 Feb 2022 14:49:24 +0000 [thread overview]
Message-ID: <bug-68350-4-2iQhqOsUkT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-68350-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68350
--- Comment #12 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
jwakely wrote:
> Correction: they need to be the same type. We can't memcpy here:
>
> struct A { };
> struct B { B() = default; B(A) { do_stuff(); } };
>
> void (A* f, A* l, B* out) {
> std::uninitialized_copy(f, l, out);
> }
Right, in your case, the ctor `B(A)` runs user-defined code (it's not
"trivial") so obviously we can't do the optimization. But even in general, see
my 2018 blog post "Trivially-constructible-from."
https://quuxplusone.github.io/blog/2018/07/03/trivially-constructible-from/
using A2 = long long;
using B2 = int64_t; // for the sake of argument, this is "long int"
void (A* f, A* l, B* out) {
std::uninitialized_copy(f, l, out);
}
The library can't, by itself, determine that memcpy would be safe here. The
library needs help from the compiler, e.g. via a new compiler builtin
__is_trivially_constructible_from(T, U). (This is *not* the same as the
existing `is_trivially_constructible<T,U>` type trait, because blog post.)
next prev parent reply other threads:[~2022-02-24 14:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-68350-4@http.gcc.gnu.org/bugzilla/>
2020-04-09 9:31 ` redi at gcc dot gnu.org
2022-02-23 22:03 ` barry.revzin at gmail dot com
2022-02-24 12:19 ` redi at gcc dot gnu.org
2022-02-24 14:20 ` redi at gcc dot gnu.org
2022-02-24 14:45 ` redi at gcc dot gnu.org
2022-02-24 14:49 ` arthur.j.odwyer at gmail dot com [this message]
2022-02-25 9:43 ` redi at gcc dot gnu.org
2023-04-26 6:55 ` rguenth at gcc dot gnu.org
2023-07-27 9:21 ` rguenth at gcc dot gnu.org
2024-05-21 9:10 ` jakub at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-68350-4-2iQhqOsUkT@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).