This is the mail archive of the gcc-bugs@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] |
|
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 |
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |