From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B2ACF38582B0; Fri, 17 Mar 2023 11:39:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2ACF38582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679053184; bh=N5L+D74Wk9Z0DNm3jZwxmIYmeeOFGbQL5cDotIdIi7k=; h=From:To:Subject:Date:From; b=ZitV7JhRLuh1vJQSXPgF/SH6V1kWsrMJQO5M5eUbA3kPTErAoNxBJhaxFQT/hoSjz N/vDx1CJbgNWB58ZBBs9cc1KbUwo2cEa6bEQ+fY4jJmh6I4qUtDpFsxjyUbt0XmKM4 ixp0afemXFO9EQhSG8FRP+bXO5d7ig6rxdrE7H1c= From: "MikeSmith32564 at mail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109172] New: g++ calls a private destructor with the keyword throw after the try-block Date: Fri, 17 Mar 2023 11:39:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: MikeSmith32564 at mail 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109172 Bug ID: 109172 Summary: g++ calls a private destructor with the keyword throw after the try-block Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: MikeSmith32564 at mail dot com Target Milestone: --- Created attachment 54692 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54692&action=3Dedit Bug example In the attached example an instance of class Demo is constructed in-place i= n a buffer by following the natural alignment of Demo and then this instance is passed to throw. Note that Demo has a private destructor. The expected behavior when buildin= g is that g++ should return a compilation error because a private destructor can= not be called outisde of the class Demo or outside of friend declarations. The actual behavior is that the example builds successfully when g++ -std=3Dc++11 ./main.cpp -o ./main is used, producing the following output: Demo(), id =3D 1 Demo(const Demo&) called, this->id =3D 2, other.id =3D 1 in catch, e.id =3D 2 ~Demo(), id =3D 2 main ends here If the destructor is instead declared as deleted the example fails to compi= le as expected: main.cpp: In function 'int main()': main.cpp:69:10: error: use of deleted function 'Demo::~Demo()' throw *d; ^ main.cpp:61:2: note: declared here ~Demo() =3D delete; ^=