public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "matthijsvanduin at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/70796] [DR 1030] Initialization order with braced-init-lists still broken Date: Wed, 03 Nov 2021 13:30:02 +0000 [thread overview] Message-ID: <bug-70796-4-qJXDPZ32vv@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-70796-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70796 Matthijs van Duin <matthijsvanduin at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matthijsvanduin at gmail dot com --- Comment #3 from Matthijs van Duin <matthijsvanduin at gmail dot com> --- This specifically appears to happen when the constructor has parameters of trivially copyable non-reference types, e.g. this fails: #include <assert.h> struct IntWrap { int x = 0; IntWrap &operator ++() { ++x; return *this; } }; struct Pair { IntWrap first, second; Pair( IntWrap x, IntWrap y ) : first{ x }, second{ y } { } }; int main() { IntWrap i; Pair p{ ++i, ++i }; assert( p.first.x == 1 && p.second.x == 2 ); // FAIL (p.first.x is 2) } but adding a destructor to IntWrap suffices to make it pass. Interestingly, when using simple ints there also appear to be very narrow constraints on the initializer arguments to trigger the bug: #include <assert.h> struct IntPair { int first, second; IntPair( int x, int y ) : first{ x }, second{ y } { } }; void testcase_fail() { int i = 0; IntPair p{ ++i, ++i }; assert( p.first == 1 && p.second == 2 ); // FAIL (p.first is 2) } void testcase_ok_1() { int i = 0; IntPair p{ ++i, ++i }; assert( p.first == 1 && p.second == 2 ); // ok int &j = i; IntPair q{ ++j, ++j }; assert( q.first == 3 && q.second == 4 ); // ok } void testcase_ok_2() { int i = 0; IntPair p{ (int &)++i, (int &)++i }; assert( p.first == 1 && p.second == 2 ); // ok } int main() { testcase_ok_1(); testcase_ok_2(); testcase_fail(); } even though the analogous testcases for IntWrap all fail. Related: bug 51253 (was supposed to have fixed this but evidently missed some cases) bug 65866 (incorrect -Wsequence-point diagnostic still being emitted) bug 70792 (dup of bug 65866 but discussion in comments covered this case)
next parent reply other threads:[~2021-11-03 13:30 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-70796-4@http.gcc.gnu.org/bugzilla/> 2021-11-03 13:30 ` matthijsvanduin at gmail dot com [this message] 2021-11-03 13:46 ` jason at gcc dot gnu.org 2021-11-03 18:56 ` jakub at gcc dot gnu.org 2021-11-03 19:42 ` jakub at gcc dot gnu.org 2021-11-19 9:09 ` cvs-commit at gcc dot gnu.org 2021-11-19 9:13 ` jakub at gcc dot gnu.org 2021-11-29 8:50 ` cvs-commit at gcc dot gnu.org 2022-05-10 8:21 ` cvs-commit at gcc dot gnu.org 2022-05-11 6:23 ` cvs-commit at gcc dot gnu.org 2022-05-11 6:32 ` 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-70796-4-qJXDPZ32vv@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).