From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1F17D3894C15; Thu, 13 May 2021 13:03:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F17D3894C15 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/86385] calling wrong constructors? Date: Thu, 13 May 2021 13:03:04 +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: 9.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cf_reconfirmed_on 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: Thu, 13 May 2021 13:03:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D86385 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2018-07-03 00:00:00 |2021-5-13 --- Comment #3 from Jonathan Wakely --- It's not calling the wrong constructor, GCC is just making a trivial copy of the object (without using any constructor) for the second operand of the ?: expression. That is never constructed using a constructor, but it is destro= yed, which causes the double free. ;; Function main (main, funcdef_no=3D14, decl_uid=3D2419, cgraph_uid=3D15, symbol_order=3D14) (executed once) int main () { struct A D.2421; struct A D.2423; void * _8; [local count: 1073741824]: D.2421 =3D{v} {CLOBBER}; _8 =3D operator new (4); MEM[(int *)_8] =3D 42; D.2421.a =3D _8; __builtin_printf ("C %p\n", &D.2421); D.2423 =3D D.2421; A::~A (&D.2423); D.2423 =3D{v} {CLOBBER}; A::~A (&D.2421); D.2421 =3D{v} {CLOBBER}; return 0; }=