public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101961] New: Missing returned object destructor call after exception throw
@ 2021-08-18 14:34 mbtrash at yandex dot ru
2022-01-06 14:31 ` [Bug c++/101961] " jason at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: mbtrash at yandex dot ru @ 2021-08-18 14:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101961
Bug ID: 101961
Summary: Missing returned object destructor call after
exception throw
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mbtrash at yandex dot ru
Target Milestone: ---
14.3.2 Exception handling:Constructors and destructors:2
(https://eel.is/c++draft/except.ctor#2)
says
"If an exception is thrown during the destruction of temporaries or local
variables for a return statement ([stmt.return]), the destructor for the
returned object (if any) is also invoked"
And it contains example (https://eel.is/c++draft/except.ctor#example-1) with
description
"...the local variable y is destroyed, causing stack unwinding, resulting in
the destruction of the returned object, ..."
Trying to recreate this example with following code
#include <iostream>
using namespace std;
struct S{
int i = 123;
S(int i) :i(i) {cout<<"S("<<i<<")"<<endl;}
~S() {cout<<"~S("<<i<<")"<<endl;}
};
struct T {
T() {cout<<"T()"<<endl;}
~T() noexcept(false) {
cout<<"~T()"<<endl;
throw 0;
}
};
S foo() {
try {
T t;
return {3};
} catch (...){}
return {4};
}
int main() {
foo();
}
Output doesn't have S{3}'s (returned object) destruction line:
T()
S(3)
~T()
S(4)
~S(4)
while should be
T()
S(3)
~T()
~S(3) <-----!
S(4)
~S(4)
Link to godbolt:
https://godbolt.org/z/hP9z5rYKG
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/101961] Missing returned object destructor call after exception throw
2021-08-18 14:34 [Bug c++/101961] New: Missing returned object destructor call after exception throw mbtrash at yandex dot ru
@ 2022-01-06 14:31 ` jason at gcc dot gnu.org
0 siblings, 0 replies; 2+ 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=101961
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
CC| |jason at gcc dot gnu.org
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
Same issue as comment 15 in 33799, which I am fixing now.
*** This bug has been marked as a duplicate of bug 33799 ***
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-06 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 14:34 [Bug c++/101961] New: Missing returned object destructor call after exception throw mbtrash at yandex dot ru
2022-01-06 14:31 ` [Bug c++/101961] " jason 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).