C:\...>gcc -v Using built-in specs. Target: djgpp Configured with: /v203/gcc-4.32/configure msdosdjgpp Thread model: single gcc version 4.3.2 (GCC)
Build command line: gpp -oexcpt -DTESTBADE excpt.C Execute command line: excpt The following source code is a pared down version of a short program I wrote to try the boundaries of the functions in <exception>. An exception object's constructor itself throws and catches an exception. After that, uncaught_exception always returns true. In the "Output:" comment at the end of the source file, places where uncaught_exception should return false are marked with "!!!". // excpt.C uses exceptions in strange and unusual ways // // build command line: gpp -oexcpt -DTESTBADE excpt.C // execute command line: excpt #include <iostream> #include <exception> void uncaught(int i = 0) { std::cerr << "[" << i <<"] std::uncaught_exception() = " << std::boolalpha << std::uncaught_exception() << std::endl; } class E { const char* descr; public: E(const char* str): descr(str) { std::cerr << "E::E(\"" << descr << "\")\n"; uncaught(); } E(const E& e): descr(e.descr) { std::cerr << "E::E(const E&)\n"; uncaught(); } ~E() { std::cerr << "E::~E()\n"; uncaught(); } const char* describe() { return descr; } }; /*****************************************************/ #ifdef TESTBADE class BadE { const char* str; public: BadE(const char* s) try : str(s) { std::cerr << "BadE::BadE(const char*) throwing \"thrown by Bade::BadE(const char*)\"\n"; throw "thrown by BadE::BadE(const char*)"; } catch (const char* str) { std::cerr << "BadE::BadE(const char*) caught \"" << str << "\"\n"; } ~BadE() { std::cerr << "BadE::~BadE()\n"; } const char* describe() { return str; } }; void throwBadE() { std::cerr << "throwBadE(): throw BadE(\"thrown by throwBadE()\")\n"; throw BadE("thrown by throwBadE()"); } #endif /*****************************************************/ void x(int i) { try { std::cerr << "[" << i <<"] x(int) throwing E(\"E from x(int) try block\")\n"; throw E("E from x(int) try block"); } catch (E e) { std::cerr << "[" << i <<"] x(int) entering catch (E) block\n"; uncaught(i); std::cerr << "[" << i <<"] x(int) caught E(\"" << e.describe() << "\") by value\n"; uncaught(i); std::cerr << "[" << i <<"] x(int) exiting catch (E) block\n"; } std::cerr << "[" << i << "] x(int) tries uncaught before exiting\n"; uncaught(i); } int main() { x(1); #ifdef TESTBADE /*****************************************************/ std::cerr << "*****************************************************\n"; try { std::cerr << "main() calling void throwBadE();\n"; try { throwBadE(); } catch (BadE& be) { std::cerr << "catch (BadE&) block => \"" << be.describe() << "\"\n"; } catch (const char* str) { std::cerr << "catch (const char*) block: " << str << "\n"; } catch (...) { std::cerr << "catch (...) block after calling void throwBadE();\n"; } } catch (...) { std::cerr << "catch (...) looking for leftover exceptions ???\n"; } /*****************************************************/ #endif std::cerr << "*****************************************************\n"; x(2); std::cerr << "*****************************************************\n"; std::cerr << "before returning from main() check uncaught\n"; uncaught(3); } /* Output: [1] x(int) throwing E("E from x(int) try block") E::E("E from x(int) try block") [0] std::uncaught_exception() = true E::E(const E&) [0] std::uncaught_exception() = true [1] x(int) entering catch (E) block [1] std::uncaught_exception() = false [1] x(int) caught E("E from x(int) try block") by value [1] std::uncaught_exception() = false [1] x(int) exiting catch (E) block E::~E() [0] std::uncaught_exception() = false E::~E() [0] std::uncaught_exception() = false [1] x(int) tries uncaught before exiting [1] std::uncaught_exception() = false ***************************************************** main() calling void throwBadE(); throwBadE(): throw BadE("thrown by throwBadE()") BadE::BadE(const char*) throwing "thrown by Bade::BadE(const char*)" BadE::BadE(const char*) caught "thrown by BadE::BadE(const char*)" catch (const char*) block: thrown by BadE::BadE(const char*) ***************************************************** [2] x(int) throwing E("E from x(int) try block") E::E("E from x(int) try block") [0] std::uncaught_exception() = true E::E(const E&) [0] std::uncaught_exception() = true [2] x(int) entering catch (E) block [2] std::uncaught_exception() = true !!! [2] x(int) caught E("E from x(int) try block") by value [2] std::uncaught_exception() = true !!! [2] x(int) exiting catch (E) block E::~E() [0] std::uncaught_exception() = true !!! E::~E() [0] std::uncaught_exception() = true !!! [2] x(int) tries uncaught before exiting [2] std::uncaught_exception() = true !!! ***************************************************** before returning from main() check uncaught [3] std::uncaught_exception() = true !!! */ -- Summary: uncaught_exception always returns true Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: trivial Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: wwashby at earthlink dot net GCC build triplet: same GCC host triplet: Microsoft Windows XP Home Edition, x86 Family 16 Model 2 Steppin GCC target triplet: same http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41174