public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109172] New: g++ calls a private destructor with the keyword throw after the try-block
@ 2023-03-17 11:39 MikeSmith32564 at mail dot com
  2023-03-17 11:50 ` [Bug c++/109172] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: MikeSmith32564 at mail dot com @ 2023-03-17 11:39 UTC (permalink / raw)
  To: gcc-bugs

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;
  ^

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-03-18  9:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 11:39 [Bug c++/109172] New: g++ calls a private destructor with the keyword throw after the try-block MikeSmith32564 at mail dot com
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

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).