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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ 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; 9+ 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] 9+ messages in thread

end of thread, other threads:[~2004-10-15  2:20 UTC | newest]

Thread overview: 9+ 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

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