http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47072
Summary: exceptions hang in c++ programs compiled by g++-4.5.2 with -O2 Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: hbjbb...@yahoo.co.jp Dear Developers of GCC, This is a bug report of gcc-4.5.2 (powerpc-apple-darwin9.8.0) relating with the -O2 optimization. When the -O2 optimization is used to compile some C++ programs, exceptions hang forever. gcc-4.5.2 is natively built from source code on my Macintosh (PowerBook G4, MacOS X 10.5.8 (Leopard)). This bug is originally found, when gcc-4.5.2 is used to compile gmp-5.0.1. In "make check", a C++ program "t-assign" hangs forever. >From the source code "t-assign.cc", I have prepared a minimal example program "demo.C" to reproduce the bug in order to write this report. Please look and see the following log list. ------------------------------------------------------------------------------- [wisdom3:~/work/425:1] adachi% uname -a Darwin wisdom3.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh [wisdom3:~/work/425:2] adachi% which g++ /usr/local/bin/g++ [wisdom3:~/work/425:3] adachi% g++ --version g++ (GCC) 4.5.2 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [wisdom3:~/work/425:4] adachi% ls ./ ../ demo.C [wisdom3:~/work/425:5] adachi% cat demo.C #include <iostream> #include <stdexcept> #include <cassert> int f(int x, int y) { std::cout << "Here is in f()." << std::endl; return -1; } class C { private: int x; public: C & operator=(int y) { if (f(x, y) != 0) throw std::invalid_argument ("C"); return *this; } }; int main(int argc, char** argv) { std::cout << "check point <1>" << std::endl; { try { C c; c = 1; assert(false); /* should not be reached */ } catch (std::invalid_argument) { } } std::cout << "check point <2>" << std::endl; { try { C c; c = 2; assert(false); /* should not be reached */ } catch (std::invalid_argument) { } } std::cout << "check point <3>" << std::endl; return 0; } [wisdom3:~/work/425:6] adachi% g++ demo.C [wisdom3:~/work/425:7] adachi% ./a.out check point <1> Here is in f(). check point <2> Here is in f(). check point <3> [wisdom3:~/work/425:8] adachi% rm a.out remove a.out? y [wisdom3:~/work/425:9] adachi% g++ -O demo.C [wisdom3:~/work/425:10] adachi% ./a.out check point <1> Here is in f(). check point <2> Here is in f(). check point <3> [wisdom3:~/work/425:11] adachi% rm a.out remove a.out? y [wisdom3:~/work/425:12] adachi% g++ -O2 demo.C [wisdom3:~/work/425:13] adachi% ./a.out check point <1> Here is in f(). check point <2> Here is in f(). ^C [wisdom3:~/work/425:14] ------------------------------------------------------------------------------- As is seen, when "demo.C" is compiled by g++ in gcc-4.5.2 without any optimization or with the "-O" optimization, the resultant executable "a.out" behaves normally and no problem occurs. However, when it is compiled with the "-O2" optimization, the resultant executable "a.out" hangs forever in its run and a break "^C" should be typed in shell. This is a serious bug affecting me and other many users of gcc. If you kindly fix this bug in some near future, I and all these users will be very happy. Sincerely yours, Satoshi Adachi