This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

exceptions in g++


Am I on crack, or should the following print "destroyed!" before being
terminated by the uncaught exception?

#include <iostream>
struct D { ~D () { std::cerr << "destroyed!" << std::endl; } };
void f () { D d; throw "oink"; }
int main () { f (); return 0; }

'cause I'm pretty sure it used to, but that's not what it does now
(with any of 4 installed versions of g++; clang is broken right now on
debian)...

Thanks,

-miles


Example (copyright notices elided):

   $ cat > dt.cc << EOF
   > #include <iostream>
   > struct D { ~D () { std::cerr << "destroyed!" << std::endl; } };
   > void f () { D d; throw "oink"; }
   > int main () { f (); return 0; }
   > EOF

   $ g++-4.4 -o dt dt.cc ; ./dt
   terminate called after throwing an instance of 'char const*'
   Aborted
   $ g++-4.4 --version
   g++-4.4 (Debian 4.4.6-9) 4.4.6

   $ g++-4.5 -o dt dt.cc ; ./dt
   terminate called after throwing an instance of 'char const*'
   Aborted
   $ g++-4.5 --version
   g++-4.5 (Debian 4.5.3-8) 4.5.3

   $ g++-4.6 -o dt dt.cc ; ./dt
   terminate called after throwing an instance of 'char const*'
   Aborted
   $ g++-4.6 --version
   g++-4.6 (Debian 4.6.1-8) 4.6.1

   $ g++-snapshot -o dt dt.cc ; ./dt
   terminate called after throwing an instance of 'char const*'
   Aborted
   $ g++-snapshot --version
   g++ (Debian 20110816-1) 4.7.0 20110816 (experimental) [trunk revision 177785]

-- 
Cat is power. ?Cat is peace.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]