From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A1E633857C5D; Wed, 3 Nov 2021 13:30:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1E633857C5D From: "matthijsvanduin at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 7.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: matthijsvanduin at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2021 13:30:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D70796 Matthijs van Duin changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matthijsvanduin at gmail d= ot com --- Comment #3 from Matthijs van Duin --- This specifically appears to happen when the constructor has parameters of trivially copyable non-reference types, e.g. this fails: #include struct IntWrap { int x =3D 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 =3D=3D 1 && p.second.x =3D=3D 2 ); // FAIL (p.fi= rst.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 struct IntPair { int first, second; IntPair( int x, int y ) : first{ x }, second{ y } { } }; void testcase_fail() { int i =3D 0; IntPair p{ ++i, ++i }; assert( p.first =3D=3D 1 && p.second =3D=3D 2 ); // FAIL (p.first = is 2) } void testcase_ok_1() { int i =3D 0; IntPair p{ ++i, ++i }; assert( p.first =3D=3D 1 && p.second =3D=3D 2 ); // ok int &j =3D i; IntPair q{ ++j, ++j }; assert( q.first =3D=3D 3 && q.second =3D=3D 4 ); // ok } void testcase_ok_2() { int i =3D 0; IntPair p{ (int &)++i, (int &)++i }; assert( p.first =3D=3D 1 && p.second =3D=3D 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)=