gcc 2.95.2 exception error, when optimizing

PETER NORDLUND peter_nordlund@swipnet.se
Mon Feb 21 13:46:00 GMT 2000


The code below behaves different (I guess faulty) 
when compiled with -O flag
compared to not having an -O flag.
Enclosed is also some .ii and .s 
files.
 
/Peter
/*-----------------------------*/
#include <iostream>
 
template <typename SINGLETON> class 
Singleton { public:   ~Singleton() { 
};                    
// NOTHROW };
 
class Base {}; class Test: public 
Singleton<Base> { public:   class CtorFailure {}; // Exception 
class.   ~Test() throw() { std::cerr << "~Test()" << 
std::endl; }   Test() {     static bool firstTime = 
true;
 
    // Simulating constructor 
failure.     if (firstTime) 
{       firstTime = 
false;       std::cerr << "Test(): Throwing 
CtorFailure" << std::endl;       throw 
CtorFailure();     }     std::cerr << 
"Test()" << std::endl;   } };
 
int main(int argc, const char** argv) 
{   Test* tp;   try {     tp = new Test; 
  } catch(const Test::CtorFailure&) {     
std::cerr << "Caught Test::Ctorfailure" << std::endl;   
}   tp = new Test;   delete tp;   std::cerr << 
"exiting main" << std::endl;   return 0;  
} /*---------------------------------*/
// What I consider to be correct 
output. src>>g++ -o a.out 
managed-singleton2-test.cpp src>>a.out Test(): Throwing 
CtorFailure Caught Test::Ctorfailure Test() ~Test() exiting 
main
 
// What I consider to be faulty 
output. src>>g++ -o a.out -O 
managed-singleton2-test.cpp src>>a.out Test(): Throwing 
CtorFailure Test() Test() ~Test() exiting main
src>>uname -a CYGWIN_NT-4.0 LILY 20.1 
(0.3/1/1) 1998-12-3 20:39:18 i586 unknown src>>g++ -v Reading specs 
from file://F/ntprog/cygwin/gcc-2.95/install-2.95.2/H-i586-cygwin32/bin/../lib/gcc-lib/i586-cygwin32/2.95.2/specs gcc 
version 2.95.2 19991024 (release) #endif
 
 
Bug1.tgz

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bug1.tgz
Type: application/x-gzip
Size: 10688 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20000221/812c50ad/attachment.bin>


More information about the Gcc-bugs mailing list