public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "richard-gccbugzilla at metafoo dot co.uk" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way Date: Mon, 07 Aug 2023 21:21:32 +0000 [thread overview] Message-ID: <bug-110938-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110938 Bug ID: 110938 Summary: miscompile if implicit special member is deleted in a subtle way Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: richard-gccbugzilla at metafoo dot co.uk Target Milestone: --- Testcase: https://godbolt.org/z/rKG8c166f ``` template<typename T> struct Error { //static_assert(false); using type = T; }; template<typename T> using ArbitraryComputation = typename Error<T>::type; struct X { template<typename T = X> X(ArbitraryComputation<T> &) = delete; X(const X&) = default; X(X&&) = delete; }; struct Y { #if 0 Y(const Y&) = default; Y(Y&&) = default; #endif mutable X x; int n; }; void print(int); Y f(); void g() { print(f().n); } ``` Uncommenting the `static_assert`, we can see that GCC never instantiates `Error<X>` in this example. But it must! If `ArbitraryComputation<X>` evaluates to `T`, then the non-trivial, templated constructor in `X` is used to copy the member `Y::x`, so `Y` is not trivially-copyable. This issue affects both type traits (GCC incorrectly evaluates `__is_trivially_copyable(Y)` to true) and code generation (GCC emits `f()` as returning in registers, which is both non-compliant with the ABI and doesn't follow the C++ language rules because `Y` has no trivial copy or move constructor). If the `#if 0` is changed to `#if 1`, the problem disappears.
next reply other threads:[~2023-08-07 21:21 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-07 21:21 richard-gccbugzilla at metafoo dot co.uk [this message] 2023-08-07 21:32 ` [Bug c++/110938] miscompile if implicit special member is deleted and mutable pinskia at gcc dot gnu.org 2023-08-07 21:35 ` [Bug c++/110938] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org 2023-08-07 21:40 ` pinskia at gcc dot gnu.org 2023-08-08 10:31 ` redi at gcc dot gnu.org 2023-08-08 19:18 ` richard-gccbugzilla at metafoo dot co.uk 2023-11-16 0:43 ` pinskia 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-110938-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).