public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "MikeSmith32564 at mail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-109172-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172 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=54692&action=edit Bug example In the attached example an instance of class Demo is constructed in-place in 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 building is that g++ should return a compilation error because a private destructor cannot be called outisde of the class Demo or outside of friend declarations. The actual behavior is that the example builds successfully when g++ -std=c++11 ./main.cpp -o ./main is used, producing the following output: Demo(), id = 1 Demo(const Demo&) called, this->id = 2, other.id = 1 in catch, e.id = 2 ~Demo(), id = 2 main ends here If the destructor is instead declared as deleted the example fails to compile 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() = delete; ^
next reply other threads:[~2023-03-17 11:39 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-17 11:39 MikeSmith32564 at mail dot com [this message] 2023-03-17 11:50 ` [Bug c++/109172] " redi at gcc dot gnu.org 2023-03-17 11:57 ` [Bug c++/109172] [10/11/12/13 Regression] " redi at gcc dot gnu.org 2023-03-17 12:21 ` rguenth at gcc dot gnu.org 2023-03-17 15:05 ` jakub at gcc dot gnu.org 2023-03-17 19:28 ` jason at gcc dot gnu.org 2023-03-17 21:32 ` cvs-commit at gcc dot gnu.org 2023-03-17 21:36 ` jason at gcc dot gnu.org 2023-03-18 3:15 ` MikeSmith32564 at mail dot com 2023-03-18 9:50 ` redi at gcc dot gnu.org 2023-03-18 9:51 ` redi 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-109172-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).