public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dawid_jurek at vp dot pl" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/94923] New: False positive -Wclass-memaccess with trivially copyable std::optional Date: Sat, 02 May 2020 13:46:08 +0000 [thread overview] Message-ID: <bug-94923-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94923 Bug ID: 94923 Summary: False positive -Wclass-memaccess with trivially copyable std::optional Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dawid_jurek at vp dot pl Target Milestone: --- Consider following C++ snippet: static_assert(std::is_trivially_copyable_v<std::optional<char>>); static void not_ok() { std::optional<char> value; std::byte buf[128; std::memcpy(&buf[0], &value, sizeof value); std::memcpy(&value, &buf[0], sizeof value); } With above snippet fresh x86-64 gcc trunk reports following warning: source>: In function 'void not_ok()': <source>:27:46: warning: 'void* memcpy(void*, const void*, size_t)' copying an object of non-trivial type 'class std::optional<char>' from an array of 'enum class std::byte' [-Wclass-memaccess] 27 | std::memcpy(&value, &buf[0], sizeof value); [basic.types]/2 explicitly permits for such round trip for every trivially copyable T via std::memcpy even if T is not trivial. Also clang accept such code without complains (take a look at link below). Changing std::byte buf[128; to char buf[128]; suppress the warning so seems that std::byte is relevant. You can find full source code here https://godbolt.org/z/JrcnS5 Regards, Dawid
next reply other threads:[~2020-05-02 13:46 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-02 13:46 dawid_jurek at vp dot pl [this message] 2020-05-02 15:38 ` [Bug c++/94923] " daniel.kruegler at googlemail dot com 2020-05-02 17:59 ` dawid_jurek at vp dot pl 2020-05-02 22:34 ` msebor at gcc dot gnu.org 2020-05-02 22:36 ` msebor at gcc dot gnu.org 2020-05-08 18:58 ` msebor at gcc dot gnu.org 2020-05-19 19:09 ` cvs-commit at gcc dot gnu.org 2020-05-21 8:31 ` dawid_jurek at vp dot pl 2022-03-17 19:53 ` msebor 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-94923-4@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: linkBe 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).