public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
@ 2013-11-28 11:18 ` redi at gcc dot gnu.org
  2013-11-28 12:15 ` temporal at gmail dot com
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: redi at gcc dot gnu.org @ 2013-11-28 11:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33799

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's now 2013 so the sensible thing to do is not return by value if your
destructor can throw.

FWIW Clang also behaves the same as G++ and Intel, and of course calls
std::terminate() in C++11 mode.


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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
  2013-11-28 11:18 ` [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws redi at gcc dot gnu.org
@ 2013-11-28 12:15 ` temporal at gmail dot com
  2020-04-20  3:30 ` mm-nospam at outlook dot co.nz
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: temporal at gmail dot com @ 2013-11-28 12:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33799

--- Comment #7 from Kenton Varda <temporal at gmail dot com> ---
> It's now 2013 so the sensible thing to do is not return by value
> if your destructor can throw.

That actually sounds like a pretty difficult rule to follow, unless you either
ban throwing destructors altogether or ban returning by value altogether.

The don't-throw-from-destructors rule is, of course, popular, but not
universally agreed upon.  I don't think this bug is the right place to debate
it (maybe try http://goo.gl/haB5nm), but I would hope that GCC wouldn't refuse
to fix a bug simply because they disagree with the coding style that triggers
that bug.

> FWIW Clang also behaves the same as G++ and Intel,

Yes, I noticed, and Clang has also had a bug filed against them which has
languished for years.  Nevertheless, the behavior is wrong.

> and of course calls std::terminate() in C++11 mode.

Unless the destructor has noexcept(false).


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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
  2013-11-28 11:18 ` [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws redi at gcc dot gnu.org
  2013-11-28 12:15 ` temporal at gmail dot com
@ 2020-04-20  3:30 ` mm-nospam at outlook dot co.nz
  2020-04-20  9:24 ` redi at gcc dot gnu.org
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: mm-nospam at outlook dot co.nz @ 2020-04-20  3:30 UTC (permalink / raw)
  To: gcc-bugs

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

mm-nospam at outlook dot co.nz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mm-nospam at outlook dot co.nz

--- Comment #14 from mm-nospam at outlook dot co.nz ---
The bug still occurs for the same test case with the f() function modified as
such:

    X f()
    {
      try {
         X x(true);
         return X(false);
      } catch(...) { }

      return X(false);
    }

The first X(false) is constructed and never destructed.

This example also occurs in [except.ctor]/2 of the C++17 standard, note that
since C++17 X's destructor should be marked as noexcept(false) in the test
case.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-04-20  3:30 ` mm-nospam at outlook dot co.nz
@ 2020-04-20  9:24 ` redi at gcc dot gnu.org
  2020-05-07 11:56 ` jakub at gcc dot gnu.org
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-20  9:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reopening. Modified version of g++.dg/eh/return1.C showing the remaining bug,
in the new i() function:

// PR c++/33799
// { dg-do run }

extern "C" void abort();

int c, d;

#if __cplusplus >= 201103L
#define THROWS noexcept(false)
#else
#define THROWS
#endif

struct X
{
  X(bool throws) : throws_(throws) { ++c; }
  X(const X& x) : throws_(x.throws_) { ++c; }
  ~X() THROWS
  {
    ++d;
    if (throws_) { throw 1; }
  }
private:
  bool throws_;
};

X f()
{
  X x(true);
  return X(false);
}

X g()
{
  return X(true),X(false);
}

void h()
{
#if __cplusplus >= 201103L
  []{ return X(true),X(false); }();
#endif
}

X i()
{
  try {
    X x(true);
    return X(false);
  } catch(...) {}
  return X(false);
}

int main()
{
  try { f(); }
  catch (...) {}

  try { g(); }
  catch (...) {}

  try { h(); }
  catch (...) {}

  try { i(); }
  catch (...) {}

  if (c != d)
    throw;
}

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-04-20  9:24 ` redi at gcc dot gnu.org
@ 2020-05-07 11:56 ` jakub at gcc dot gnu.org
  2020-07-23  6:52 ` rguenth at gcc dot gnu.org
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-07 11:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.0                        |10.2

--- Comment #16 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.1 has been released.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2020-05-07 11:56 ` jakub at gcc dot gnu.org
@ 2020-07-23  6:52 ` rguenth at gcc dot gnu.org
  2021-04-08 12:02 ` rguenth at gcc dot gnu.org
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-07-23  6:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.2                        |10.3

--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10.2 is released, adjusting target milestone.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2020-07-23  6:52 ` rguenth at gcc dot gnu.org
@ 2021-04-08 12:02 ` rguenth at gcc dot gnu.org
  2022-01-06 14:31 ` jason at gcc dot gnu.org
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-08 12:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.3                        |10.4

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10.3 is being released, retargeting bugs to GCC 10.4.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2021-04-08 12:02 ` rguenth at gcc dot gnu.org
@ 2022-01-06 14:31 ` jason at gcc dot gnu.org
  2022-01-07  0:26 ` cvs-commit at gcc dot gnu.org
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: jason at gcc dot gnu.org @ 2022-01-06 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mbtrash at yandex dot ru

--- Comment #19 from Jason Merrill <jason at gcc dot gnu.org> ---
*** Bug 101961 has been marked as a duplicate of this bug. ***

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2022-01-06 14:31 ` jason at gcc dot gnu.org
@ 2022-01-07  0:26 ` cvs-commit at gcc dot gnu.org
  2022-02-01 22:51 ` jason at gcc dot gnu.org
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-07  0:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:b10e031458d541f794dfaa08ba606487603a4bb6

commit r12-6333-gb10e031458d541f794dfaa08ba606487603a4bb6
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 5 17:01:12 2022 -0500

    c++: destroy retval on throwing cleanup in try [PR33799]

    My earlier attempt to fix this bug didn't handle the case where both the
    return and the throwing cleanup are within a try-block that catches and
    discards the exception.  Fixed by adding the retval cleanup to any
    try-blocks as well as the function body.  PR102191 pointed out that we also
    weren't handling templates properly, so I moved the call out of the parser.

            PR c++/33799
            PR c++/102191

    gcc/cp/ChangeLog:

            * except.c (maybe_splice_retval_cleanup): Check
            current_binding_level.
            * semantics.c (do_poplevel): Call it here.
            * parser.c (cp_parser_compound_statement): Not here.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add temporary in try block case.
            * g++.dg/cpp2a/constexpr-dtor11.C: New test.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2022-01-07  0:26 ` cvs-commit at gcc dot gnu.org
@ 2022-02-01 22:51 ` jason at gcc dot gnu.org
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: jason at gcc dot gnu.org @ 2022-02-01 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|10.4                        |12.0
             Status|REOPENED                    |RESOLVED

--- Comment #21 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2022-02-01 22:51 ` jason at gcc dot gnu.org
@ 2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
  2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-07  1:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #22 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:08cea4e56a094ff9cc7c65fdc9ce8c4d7aff64be

commit r14-1591-g08cea4e56a094ff9cc7c65fdc9ce8c4d7aff64be
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 6 15:31:23 2023 -0400

    c++: fix throwing cleanup with label

    While looking at PR92407 I noticed that the expectations of
    maybe_splice_retval_cleanup weren't being met; an sk_cleanup level was
    confusing its attempt to recognize the outer block of the function.  And
    even if I fixed the detection, it failed to actually wrap the body of the
    function because the STATEMENT_LIST it got only had the label, not anything
    after it.  So I moved the call after poplevel does pop_stmt_list on all the
    sk_cleanup levels.

            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Change
            recognition of function body and try scopes.
            * semantics.cc (do_poplevel): Call it after poplevel.
            (at_try_scope): New.
            * cp-tree.h (maybe_splice_retval_cleanup): Adjust.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add label cases.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
@ 2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-02 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #23 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:ae07265381d934ee97fb1ce8915731158c91babc

commit r14-5086-gae07265381d934ee97fb1ce8915731158c91babc
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 30 17:44:54 2023 -0400

    c++: retval dtor on rethrow [PR112301]

    In r12-6333 for PR33799, I fixed the example in [except.ctor]/2.  In that
    testcase, the exception is caught and the function returns again,
    successfully.

    In this testcase, however, the exception is rethrown, and hits two separate
    cleanups: one in the try block and the other in the function body.  So we
    destroy twice an object that was only constructed once.

    Fortunately, the fix for the normal case is easy: we just need to clear the
    "return value constructed by return" flag when we do it the first time.

    This gets more complicated with the named return value optimization, since
    we don't want to destroy the return value while the NRV variable is still
in
    scope.

            PR c++/112301
            PR c++/102191
            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Clear
            current_retval_sentinel when destroying retval.
            * semantics.cc (nrv_data): Add in_nrv_cleanup.
            (finalize_nrv): Set it.
            (finalize_nrv_r): Fix handling of throwing cleanups.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add more cases.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (11 preceding siblings ...)
  2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
@ 2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-17  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:65388a996d7dfcdd22ff2d191458699d1cacf254

commit r12-9988-g65388a996d7dfcdd22ff2d191458699d1cacf254
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 6 15:31:23 2023 -0400

    c++: fix throwing cleanup with label

    While looking at PR92407 I noticed that the expectations of
    maybe_splice_retval_cleanup weren't being met; an sk_cleanup level was
    confusing its attempt to recognize the outer block of the function.  And
    even if I fixed the detection, it failed to actually wrap the body of the
    function because the STATEMENT_LIST it got only had the label, not anything
    after it.  So I moved the call after poplevel does pop_stmt_list on all the
    sk_cleanup levels.

            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Change
            recognition of function body and try scopes.
            * semantics.cc (do_poplevel): Call it after poplevel.
            (at_try_scope): New.
            * cp-tree.h (maybe_splice_retval_cleanup): Adjust.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add label cases.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (12 preceding siblings ...)
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
@ 2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-17  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:7fae9873a74c7a5a62044bb6a4cde8e3ac1a5e5d

commit r12-9990-g7fae9873a74c7a5a62044bb6a4cde8e3ac1a5e5d
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 30 17:44:54 2023 -0400

    c++: retval dtor on rethrow [PR112301]

    In r12-6333 for PR33799, I fixed the example in [except.ctor]/2.  In that
    testcase, the exception is caught and the function returns again,
    successfully.

    In this testcase, however, the exception is rethrown, and hits two separate
    cleanups: one in the try block and the other in the function body.  So we
    destroy twice an object that was only constructed once.

    Fortunately, the fix for the normal case is easy: we just need to clear the
    "return value constructed by return" flag when we do it the first time.

    This gets more complicated with the named return value optimization, since
    we don't want to destroy the return value while the NRV variable is still
in
    scope.

            PR c++/112301
            PR c++/102191
            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Clear
            current_retval_sentinel when destroying retval.
            * semantics.cc (nrv_data): Add in_nrv_cleanup.
            (finalize_nrv): Set it.
            (finalize_nrv_r): Fix handling of throwing cleanups.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add more cases.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (13 preceding siblings ...)
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
@ 2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-17  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:e62dd770afde1745c547d05c8163ee5cd639464b

commit r13-8077-ge62dd770afde1745c547d05c8163ee5cd639464b
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 6 15:31:23 2023 -0400

    c++: fix throwing cleanup with label

    While looking at PR92407 I noticed that the expectations of
    maybe_splice_retval_cleanup weren't being met; an sk_cleanup level was
    confusing its attempt to recognize the outer block of the function.  And
    even if I fixed the detection, it failed to actually wrap the body of the
    function because the STATEMENT_LIST it got only had the label, not anything
    after it.  So I moved the call after poplevel does pop_stmt_list on all the
    sk_cleanup levels.

            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Change
            recognition of function body and try scopes.
            * semantics.cc (do_poplevel): Call it after poplevel.
            (at_try_scope): New.
            * cp-tree.h (maybe_splice_retval_cleanup): Adjust.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add label cases.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (14 preceding siblings ...)
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
@ 2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
  2023-12-20 17:31 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-17  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:d237e7b291ff52095d600e6489a54b4ba8aaf608

commit r13-8079-gd237e7b291ff52095d600e6489a54b4ba8aaf608
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Oct 30 17:44:54 2023 -0400

    c++: retval dtor on rethrow [PR112301]

    In r12-6333 for PR33799, I fixed the example in [except.ctor]/2.  In that
    testcase, the exception is caught and the function returns again,
    successfully.

    In this testcase, however, the exception is rethrown, and hits two separate
    cleanups: one in the try block and the other in the function body.  So we
    destroy twice an object that was only constructed once.

    Fortunately, the fix for the normal case is easy: we just need to clear the
    "return value constructed by return" flag when we do it the first time.

    This gets more complicated with the named return value optimization, since
    we don't want to destroy the return value while the NRV variable is still
in
    scope.

            PR c++/112301
            PR c++/102191
            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Clear
            current_retval_sentinel when destroying retval.
            * semantics.cc (nrv_data): Add in_nrv_cleanup.
            (finalize_nrv): Set it.
            (finalize_nrv_r): Fix handling of throwing cleanups.

    gcc/testsuite/ChangeLog:

            * g++.dg/eh/return1.C: Add more cases.

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (15 preceding siblings ...)
  2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
@ 2023-12-20 17:31 ` cvs-commit at gcc dot gnu.org
  2024-01-24 19:39 ` cvs-commit at gcc dot gnu.org
  2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-20 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #28 from GCC 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:02c0b49798228d777610f898cd9d63ebec43656d

commit r14-6754-g02c0b49798228d777610f898cd9d63ebec43656d
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]

    maybe_splice_retval_cleanup assumed that the function body can't be empty
if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.

            PR c++/113088
            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.

    gcc/testsuite/ChangeLog:

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

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (16 preceding siblings ...)
  2023-12-20 17:31 ` cvs-commit at gcc dot gnu.org
@ 2024-01-24 19:39 ` cvs-commit at gcc dot gnu.org
  2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-24 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #29 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:60bfd373a1891ae2349dc67313d104079ce8c706

commit r13-8247-g60bfd373a1891ae2349dc67313d104079ce8c706
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]

    maybe_splice_retval_cleanup assumed that the function body can't be empty
if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.

            PR c++/113088
            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.

    gcc/testsuite/ChangeLog:

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

    (cherry picked from commit 02c0b49798228d777610f898cd9d63ebec43656d)

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
       [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
                   ` (17 preceding siblings ...)
  2024-01-24 19:39 ` cvs-commit at gcc dot gnu.org
@ 2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
  18 siblings, 0 replies; 23+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-24 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #30 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:b0605cd4a12e9162cc56abc69ca1048947c72689

commit r12-10110-gb0605cd4a12e9162cc56abc69ca1048947c72689
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]

    maybe_splice_retval_cleanup assumed that the function body can't be empty
if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.

            PR c++/113088
            PR c++/33799

    gcc/cp/ChangeLog:

            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.

    gcc/testsuite/ChangeLog:

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

    (cherry picked from commit 02c0b49798228d777610f898cd9d63ebec43656d)

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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
  2007-10-17 11:31 [Bug c++/33799] New: " bitti at iki dot fi
                   ` (2 preceding siblings ...)
  2007-10-17 17:07 ` jason at gcc dot gnu dot org
@ 2008-09-19 12:14 ` bitti at iki dot fi
  3 siblings, 0 replies; 23+ messages in thread
From: bitti at iki dot fi @ 2008-09-19 12:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bitti at iki dot fi  2008-09-19 12:12 -------
(In reply to comment #3)
> Similar to Bug 15764.

I ran again into this bug in gcc 4.3.2. Any idea when there's time to fix it?

Matti Rintala


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33799


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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
  2007-10-17 11:31 [Bug c++/33799] New: " bitti at iki dot fi
  2007-10-17 12:03 ` [Bug c++/33799] " rguenth at gcc dot gnu dot org
  2007-10-17 12:21 ` bitti at iki dot fi
@ 2007-10-17 17:07 ` jason at gcc dot gnu dot org
  2008-09-19 12:14 ` bitti at iki dot fi
  3 siblings, 0 replies; 23+ messages in thread
From: jason at gcc dot gnu dot org @ 2007-10-17 17:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jason at gcc dot gnu dot org  2007-10-17 17:07 -------
Similar to Bug 15764.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jason at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-10-17 17:07:45
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33799


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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
  2007-10-17 11:31 [Bug c++/33799] New: " bitti at iki dot fi
  2007-10-17 12:03 ` [Bug c++/33799] " rguenth at gcc dot gnu dot org
@ 2007-10-17 12:21 ` bitti at iki dot fi
  2007-10-17 17:07 ` jason at gcc dot gnu dot org
  2008-09-19 12:14 ` bitti at iki dot fi
  3 siblings, 0 replies; 23+ messages in thread
From: bitti at iki dot fi @ 2007-10-17 12:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bitti at iki dot fi  2007-10-17 12:21 -------
I also tried on other compilers. Sun's compiler (CC: Sun C++ 5.9 SunOS_sparc
Patch 124863-01 2007/07/25) shows the same bug as Gcc. Microsoft Visual Studio
2005 works ok and destroys both objects.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33799


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

* [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws
  2007-10-17 11:31 [Bug c++/33799] New: " bitti at iki dot fi
@ 2007-10-17 12:03 ` rguenth at gcc dot gnu dot org
  2007-10-17 12:21 ` bitti at iki dot fi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 23+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-10-17 12:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2007-10-17 12:03 -------
As a data point, EDG based icpc behaves the same.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33799


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

end of thread, other threads:[~2024-01-24 19:40 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-33799-4@http.gcc.gnu.org/bugzilla/>
2013-11-28 11:18 ` [Bug c++/33799] Return value's destructor not executed when a local variable's destructor throws redi at gcc dot gnu.org
2013-11-28 12:15 ` temporal at gmail dot com
2020-04-20  3:30 ` mm-nospam at outlook dot co.nz
2020-04-20  9:24 ` redi at gcc dot gnu.org
2020-05-07 11:56 ` jakub at gcc dot gnu.org
2020-07-23  6:52 ` rguenth at gcc dot gnu.org
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2022-01-06 14:31 ` jason at gcc dot gnu.org
2022-01-07  0:26 ` cvs-commit at gcc dot gnu.org
2022-02-01 22:51 ` jason at gcc dot gnu.org
2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
2023-11-17  0:21 ` cvs-commit at gcc dot gnu.org
2023-12-20 17:31 ` cvs-commit at gcc dot gnu.org
2024-01-24 19:39 ` cvs-commit at gcc dot gnu.org
2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
2007-10-17 11:31 [Bug c++/33799] New: " bitti at iki dot fi
2007-10-17 12:03 ` [Bug c++/33799] " rguenth at gcc dot gnu dot org
2007-10-17 12:21 ` bitti at iki dot fi
2007-10-17 17:07 ` jason at gcc dot gnu dot org
2008-09-19 12:14 ` bitti at iki dot fi

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