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