public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception
@ 2004-06-01 17:03 boris at kolpackov dot net
2004-06-01 17:13 ` [Bug c++/15764] " pinskia at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: boris at kolpackov dot net @ 2004-06-01 17:03 UTC (permalink / raw)
To: gcc-bugs
$ cat >test.cxx
#include <cstdlib>
struct a
{
~a ()
{
throw 1;
}
};
int
f (a const& acr = a ())
{
return 1;
}
struct b
{
b (int)
{
}
~b ()
{
std::abort ();
}
};
int
main ()
{
try
{
b b_ (f ());
}
catch (...) {}
}
$ g++ -v
Reading specs from /home/boris/local/lib/gcc/x86_64-unknown-linux-gnu/3.4.0/specs
Configured with: /home/boris/gcc-3.4.0/configure --prefix=/home/boris/local
--enable-__cxa_atexit --enable-languages=c,c++ --enable-long-long
--with-system-zlib --enable-shared --disable-multilib
Thread model: posix
gcc version 3.4.0
$ g++ test.cxx
$ ./a.out
I tried it on Intel C++ 8.0 and Compaq C++ 6.5-040 and they both call b::~b.
-boris
--
Summary: no cleanup if temporary's dtor terminates with an
exception
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: boris at kolpackov dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
@ 2004-06-01 17:13 ` pinskia at gcc dot gnu dot org
2004-06-01 17:45 ` bangerth at dealii dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-01 17:13 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-01 17:13 -------
b b_ (f ());
b is not initialized when ~a throws as it is equivant to
int i;
{
const a &c= a();
i = f(c);
}
b b_ (i);
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
2004-06-01 17:13 ` [Bug c++/15764] " pinskia at gcc dot gnu dot org
@ 2004-06-01 17:45 ` bangerth at dealii dot org
2004-06-01 17:53 ` boris at kolpackov dot net
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-06-01 17:45 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-06-01 17:45 -------
Andrew is right: b::b() isn't called (as you can easily verify by
placing another call to std::abort into the constructor). Thus,
there shouldn't be any call to the destructor either.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
2004-06-01 17:13 ` [Bug c++/15764] " pinskia at gcc dot gnu dot org
2004-06-01 17:45 ` bangerth at dealii dot org
@ 2004-06-01 17:53 ` boris at kolpackov dot net
2004-06-01 18:15 ` bangerth at dealii dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: boris at kolpackov dot net @ 2004-06-01 17:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From boris at kolpackov dot net 2004-06-01 17:52 -------
$ cat >test.cxx
#include <iostream>
using std::cerr;
using std::endl;
struct a
{
~a ()
{
throw 1;
}
};
int
f (a const& acr = a ())
{
return 1;
}
struct b
{
b (int)
{
cerr << "b" << endl;
}
~b ()
{
cerr << "~b" << endl;
// std::abort ();
}
};
int
main ()
{
try
{
b b_ (f ());
}
catch (...) {}
}
$ g++ test.cxx
$ ./a.out
b
$ #?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
` (2 preceding siblings ...)
2004-06-01 17:53 ` boris at kolpackov dot net
@ 2004-06-01 18:15 ` bangerth at dealii dot org
2004-06-01 18:16 ` bangerth at dealii dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-06-01 18:15 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-06-01 18:15 -------
Alright, I shouldn't first reduce and then draw conclusions. The
call to f() is the necessary step. Here is a slightly smaller testcase:
------------------
extern "C" void abort ();
int counter = 0;
struct a {
~a () { throw 1; }
};
int f (a const&) { return 1; }
struct b {
b (...) { ++counter; }
~b () { --counter; }
};
int main () {
try { b tmp(f (a())); }
catch (...) {}
if (counter != 0)
abort ();
}
--------------
In
b tmp(f(a()));
the call to a::a() throws, so f return prematurely, and we shouldn't
even start to construct tmp. However, we do, thus incrementing the
counter. Then we fail to run the destructor, though.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
` (3 preceding siblings ...)
2004-06-01 18:15 ` bangerth at dealii dot org
@ 2004-06-01 18:16 ` bangerth at dealii dot org
2004-06-01 18:18 ` boris at kolpackov dot net
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-06-01 18:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-06-01 18:16 -------
Confirmed, indeed, with 2.95 through mainline.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-06-01 18:16:26
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
` (4 preceding siblings ...)
2004-06-01 18:16 ` bangerth at dealii dot org
@ 2004-06-01 18:18 ` boris at kolpackov dot net
2004-06-01 18:29 ` bangerth at dealii dot org
2004-10-15 2:20 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 12+ messages in thread
From: boris at kolpackov dot net @ 2004-06-01 18:18 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From boris at kolpackov dot net 2004-06-01 18:18 -------
> the call to a::a() throws
^^^^^^
a::~a()
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
` (5 preceding siblings ...)
2004-06-01 18:18 ` boris at kolpackov dot net
@ 2004-06-01 18:29 ` bangerth at dealii dot org
2004-10-15 2:20 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-06-01 18:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-06-01 18:29 -------
Gee, yes, I can't seem to read code today. Since the lifetime
of the temporary a() is until the end of the expression, the
variable tmp is fully constructed. It needs to be destroyed
again as part of the cleanup to be done when a::~a throws,
but isn't.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
` (6 preceding siblings ...)
2004-06-01 18:29 ` bangerth at dealii dot org
@ 2004-10-15 2:20 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-15 2:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-15 02:20 -------
The try/finally block for the tmp is not around the initializer, why?
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Last reconfirmed|2004-06-01 18:16:26 |2004-10-15 02:20:26
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
[not found] <bug-15764-5779@http.gcc.gnu.org/bugzilla/>
2007-09-06 5:36 ` jason at gcc dot gnu dot org
2007-10-03 10:44 ` jason at gcc dot gnu dot org
@ 2007-10-03 18:26 ` jason at gcc dot gnu dot org
2 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2007-10-03 18:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from jason at gcc dot gnu dot org 2007-10-03 18:26 -------
Fixed for 4.3.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Known to fail|4.3.0 |
Known to work| |4.3.0
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
[not found] <bug-15764-5779@http.gcc.gnu.org/bugzilla/>
2007-09-06 5:36 ` jason at gcc dot gnu dot org
@ 2007-10-03 10:44 ` jason at gcc dot gnu dot org
2007-10-03 18:26 ` jason at gcc dot gnu dot org
2 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2007-10-03 10:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from jason at gcc dot gnu dot org 2007-10-03 10:43 -------
Subject: Bug 15764
Author: jason
Date: Wed Oct 3 10:43:42 2007
New Revision: 128979
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128979
Log:
PR c++/15764
* cp/decl.c (wrap_cleanups_r): New fn.
(wrap_temporary_cleanups): New fn.
(initialize_local_var): Call it.
* tree-eh.c (same_handler_p): New fn.
(optimize_double_finally): New fn.
(refactor_eh_r): New fn.
(refactor_eh): New fn.
(pass_refactor_eh): New pass.
* tree-pass.h: Declare it.
* passes.c (init_optimization_passes): Add it.
Added:
trunk/gcc/testsuite/g++.dg/eh/init-temp1.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/passes.c
trunk/gcc/tree-eh.c
trunk/gcc/tree-pass.h
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15764] no cleanup if temporary's dtor terminates with an exception
[not found] <bug-15764-5779@http.gcc.gnu.org/bugzilla/>
@ 2007-09-06 5:36 ` jason at gcc dot gnu dot org
2007-10-03 10:44 ` jason at gcc dot gnu dot org
2007-10-03 18:26 ` jason at gcc dot gnu dot org
2 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2007-09-06 5:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from jason at gcc dot gnu dot org 2007-09-06 05:36 -------
This version of the test breaks under ICC:
----------------------
extern "C" void abort ();
int counter = 0;
int thrown = 0;
struct a {
~a () { if (!thrown++) throw 1; }
};
int f (a const&, const a&) { return 1; }
struct b {
b (...) { ++counter; }
~b () { --counter; }
};
void g();
int main () {
try {
b tmp(f (a(), a()));
}
catch (...) {}
if (counter != 0)
abort ();
}
----------------------
For whatever reason, if the first ~a throws, ICC doesn't try to destroy tmp,
but if the second ~a throws, ICC cleans up tmp properly. Odd.
--
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|NEW |ASSIGNED
Last reconfirmed|2005-06-19 15:11:05 |2007-09-06 05:36:24
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15764
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2007-10-03 18:26 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-01 17:03 [Bug c++/15764] New: no cleanup if temporary's dtor terminates with an exception boris at kolpackov dot net
2004-06-01 17:13 ` [Bug c++/15764] " pinskia at gcc dot gnu dot org
2004-06-01 17:45 ` bangerth at dealii dot org
2004-06-01 17:53 ` boris at kolpackov dot net
2004-06-01 18:15 ` bangerth at dealii dot org
2004-06-01 18:16 ` bangerth at dealii dot org
2004-06-01 18:18 ` boris at kolpackov dot net
2004-06-01 18:29 ` bangerth at dealii dot org
2004-10-15 2:20 ` pinskia at gcc dot gnu dot org
[not found] <bug-15764-5779@http.gcc.gnu.org/bugzilla/>
2007-09-06 5:36 ` jason at gcc dot gnu dot org
2007-10-03 10:44 ` jason at gcc dot gnu dot org
2007-10-03 18:26 ` jason at gcc dot gnu dot 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).