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

* [Bug c++/109172] g++ calls a private destructor with the keyword throw after the try-block
  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 ` 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
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-17 11:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-03-17
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |accepts-invalid

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The attached example has the deleted destructor, so fails as expected.

Reduced version of the actual problem:

struct Demo
{
private:

  ~Demo()
  {
    __builtin_abort();
  }
};

int main() {
  try
  {
    throw *new Demo;
  }
  catch(const Demo& e)
  {
  }
}

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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 ` redi at gcc dot gnu.org
  2023-03-17 12:21 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-17 11:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |13.0, 4.4.7
      Known to work|                            |4.1.2, 4.3.0
            Summary|g++ calls a private         |[10/11/12/13 Regression]
                   |destructor with the keyword |g++ calls a private
                   |throw after the try-block   |destructor with the keyword
                   |                            |throw after the try-block

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a regression that started after r156840 and no later than r156854

Maybe r156841 or r156842

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-17 12:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.5

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-17 15:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Given that the class is empty, my bet from those two would be on r156842.
Anyway, if I add int d; before private: in #c1, it started to be accepted only
in
r159428 aka DR475 I think (r159421 still rejects, r159430 accepts).

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (3 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2023-03-17 19:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-17 21:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:890043314a7f405081990ea9d0cb577dd44f883f

commit r13-6742-g890043314a7f405081990ea9d0cb577dd44f883f
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 17 15:27:10 2023 -0400

    c++: throw and private destructor [PR109172]

    Since we aren't going through the normal call machinery, we need to check
    the dtor access specifically.

            PR c++/109172

    gcc/cp/ChangeLog:

            * except.cc (build_throw): Check dtor access.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/dtor4.C: New test.

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2023-03-17 21:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |13.0
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 13.  In general I'm not inclined to backport accepts-invalid
fixes, but am open to discussion.

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: MikeSmith32564 at mail dot com @ 2023-03-18  3:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

--- Comment #6 from Mike Smith <MikeSmith32564 at mail dot com> ---
(In reply to CVS Commits from comment #4)
> The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
> 
> https://gcc.gnu.org/g:890043314a7f405081990ea9d0cb577dd44f883f
> 
> commit r13-6742-g890043314a7f405081990ea9d0cb577dd44f883f
> Author: Jason Merrill <jason@redhat.com>
> Date:   Fri Mar 17 15:27:10 2023 -0400
> 
>     c++: throw and private destructor [PR109172]
>     
>     Since we aren't going through the normal call machinery, we need to check
>     the dtor access specifically.
>     
>             PR c++/109172
>     
>     gcc/cp/ChangeLog:
>     
>             * except.cc (build_throw): Check dtor access.
>     
>     gcc/testsuite/ChangeLog:
>     
>             * g++.dg/eh/dtor4.C: New test.

Thank you for addressing this quickly, I don't know if backporting will be
necessary,

About the test written in dtor4.C,

I don't know how testing is supposed to work, but if the goal is to confirm
that this fails to compile and link, linking will fail due to a missing
implementation, and since now, compiling will fail due to the private
destructor, so no matter what this will fail to build, shouldn't the body of
the destructor here be defined like

~Demo()
{

}

this?

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-18  9:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No. This line means the test has to exit with an error referring to that line
of the source, and it must contain the string "private":

      throw *new Demo;          // { dg-error private }

If it compiles without a matching error, the test fails. It doesn't matter
whether it links successfully or not.

In any case, the default action for compiler tests is to compile them, and not
try to link, so it would never give a linker error even if the expected
compilation error is absent.

https://gcc.gnu.org/onlinedocs/gccint/Directives.html documents the default
action, which is { dg-do compile }.

If the test contained { dg-do link } or { dg-do run } then there would be a
linker error if the private destructor wasn't diagnosed, but that still
wouldn't match the expected error on line 12.

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

* [Bug c++/109172] [10/11/12/13 Regression] g++ calls a private destructor with the keyword throw after the try-block
  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
                   ` (8 preceding siblings ...)
  2023-03-18  9:50 ` redi at gcc dot gnu.org
@ 2023-03-18  9:51 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-18  9:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109172

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #5)
> Fixed for GCC 13.  In general I'm not inclined to backport accepts-invalid
> fixes, but am open to discussion.

The fact nobody reported it until now suggests it's not a big deal.

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