public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vania at liama dot ia dot ac dot cn" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/35898] New: C++ exception bug at run time when mutually recursive functions Date: Thu, 10 Apr 2008 03:23:00 -0000 [thread overview] Message-ID: <bug-35898-16041@http.gcc.gnu.org/bugzilla/> (raw) Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnu Thread model: posix gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) The following is a C++ program that shows the problem. It is a program that always end up with an exception sooner or later based on the input value... Compilation with -ansi -Wall works fine and report no errors and warning. First run the program with input '1000' (argument on command line). It works fine. The exception is caught properly. Run the program with input 1. The program aborts because the exception is thrown but not caught. The program has 4 functions which can be mutually recursive based on the input value. When there is mutual recursion between only 2 functions it works fine, the exception is thrown and the appropriate catch clause operates. When there is mutual recursion between more than 2 functions, when the exception is thrown, it not caught as it should and it goes into terminate... #include <iostream> #include <cstdlib> using namespace std; unsigned int seed; unsigned int my_random() { unsigned int low = 16807 * (seed & 0xffff); unsigned int high = 16807 * (seed >> 16); low += (high &0x7FFF) << 16; low += high >> 15; if (low > 0x7FFFFFFF) low -= 0x7FFFFFFF; return (seed = low); } const unsigned int small_max = 0xFFF; const unsigned int medium_max = 0xFFFFF; unsigned int small_size = 0; unsigned int medium_size = small_max; unsigned int large_size = medium_max; void dummy_test(); class MyException { public: const char *msg; MyException(const char * s):msg(s){}; }; // MyException::MyException(const char *s):msg(s){}; class SmallException: public MyException { public: SmallException(const char *s, int r); int small; }; SmallException::SmallException(const char * s, int r): MyException(s) { small = r; } class MediumException: public MyException { public: MediumException(const char * s, int r); int medium; }; MediumException::MediumException(const char * s, int r): MyException(s) { medium = r; } class LargeException: public MyException { public: LargeException(const char *s, int r); int large; }; LargeException::LargeException(const char *s, int r): MyException(s) { large = r; } void small(unsigned int v) throw (SmallException &) { small_size = small_size << 1; cout << "small ? " << v << endl; if (small_size >= v) throw SmallException("small test fails : ", v); else dummy_test(); } void medium(unsigned int v) throw (MediumException &) { medium_size = medium_size << 1; cout << "medium ? " << v << endl; if (medium_size >= v) throw MediumException("medium test fails : ", v); else dummy_test(); } void large(unsigned int v) throw (LargeException &) { large_size = large_size << 1; cout << "large ? " << v << endl; if (large_size >= v) throw LargeException("large test fails : ", v); else dummy_test(); } void dummy_test() { unsigned int v = my_random(); if (v < small_max) small(v); else if (v > medium_max) large(v); else medium(v); } void test_exception(){ try { dummy_test(); } catch ( SmallException &e) { cout << "Exception -- " << e.msg << e.small << endl; } catch ( MediumException &e ) { cout << "Exception -- " << e.msg << e.medium << endl; } catch ( LargeException &e) { cout << "Exception -- " << e.msg << e.large << endl; } catch (...) { cout << "Unspecified exception type\n" << endl; }; } int main(int argc, char* argv[]) { if (argc < 2 || (seed = atoi(argv[1])) == 0) { cout << "Must have valid number argument" << endl; return 0; } cout << "start test with seed " << seed << endl; test_exception(); cout << "test ending normally " << endl; return 0; } -- Summary: C++ exception bug at run time when mutually recursive functions Product: gcc Version: 4.1.3 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vania at liama dot ia dot ac dot cn GCC host triplet: x86_64 GNU/Linux 2.6.22-14- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35898
next reply other threads:[~2008-04-10 3:23 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-04-10 3:23 vania at liama dot ia dot ac dot cn [this message] 2008-04-10 3:34 ` [Bug c++/35898] " vania at liama dot ia dot ac dot cn 2008-04-10 10:40 ` rguenth at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-35898-16041@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).