The following code crashes g++ 4.1.3 : *********START OF FILE************** #include <iostream> using namespace std; double arctan(double x) { int i=1,n=20; double c=1.0,arct=0.0,paf=1.0,eps=0.00001,hab; hab=(x/(1+x*x)); do { arct+=paf; c+=2i/(2i+1); paf=(c*hab); i++; } while((i<n)||(paf>eps)); arct*=hab; return arct; } int main() { double Pi; Pi=4*(4*arctan(1/5)-arctan(1/239)); cout<<Pi<<endl; } ********* END OF FILE ************** And here's the output of g++ : nmaquet@nmaquet-desktop:/tmp$ g++ -v test.cpp Using built-in specs. Target: i486-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 i486-linux-gnu Thread model: posix gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) /usr/lib/gcc/i486-linux-gnu/4.1.3/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -auxbase test -version -fstack-protector -fstack-protector -o /tmp/ccQX7fQO.s ignoring nonexistent directory "/usr/local/include/i486-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../i486-linux-gnu/include" ignoring nonexistent directory "/usr/include/i486-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.1.3 /usr/include/c++/4.1.3/i486-linux-gnu /usr/include/c++/4.1.3/backward /usr/local/include /usr/lib/gcc/i486-linux-gnu/4.1.3/include /usr/include End of search list. GNU C++ version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) (i486-linux-gnu) compiled by GNU C version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 3cc47be363985179cfafdceddd0e8f5d test.cpp: In function ‘double arctan(double)’: test.cpp:12: internal compiler error: in const_binop, at fold-const.c:1641 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. For Debian GNU/Linux specific bug reporting instructions, see <URL:file:///usr/share/doc/gcc-4.1/README.Bugs>. Preprocessed source stored into /tmp/cczf63dY.out file, please attach this to your bugreport.
Created attachment 14547 [details] preprocessed source
I reported this on Launchpad a few weeks ago but it doesn't get much attention : https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/155259
4.0.1 (apple) ICEs: pr34086.cc: In function 'double arctan(double)': pr34086.cc:12: internal compiler error: in const_binop, at fold-const.c:1610 4.2.2 gives me: pr34086.cc: In function 'double arctan(double)': pr34086.cc:12: error: cannot convert 'double __complex__' to 'double' in assignment
Confirmed. #1 0x084a545e in const_binop (code=TRUNC_DIV_EXPR, arg1=0xb7cec528, arg2=0xb7cec720, notrunc=0) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:1640 1640 default: (gdb) l 1635 real = const_binop (code, t1, magsquared, notrunc); 1636 imag = const_binop (code, t2, magsquared, notrunc); 1637 } 1638 break; 1639 1640 default: 1641 gcc_unreachable (); 1642 } 1643 1644 if (real && imag) both args are COMPLEX_CST which are not valid for TRUNC_DIV_EXPR. #1 0x084a545e in const_binop (code=TRUNC_DIV_EXPR, arg1=0xb7cec528, arg2=0xb7cec720, notrunc=0) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:1640 #2 0x084d63be in fold_binary (code=TRUNC_DIV_EXPR, type=0xb7cea844, op0=0xb7cec528, op1=0xb7cec720) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:7626 #3 0x084f4704 in fold (expr=0xb7c4d2ac) at /home/richard/src/gcc-4_1-branch/gcc/fold-const.c:10303 #4 0x081e0b06 in fold_if_not_in_template (expr=0xb7c4d2ac) at /home/richard/src/gcc-4_1-branch/gcc/cp/tree.c:2334 #5 0x0818c0cb in build_binary_op (code=TRUNC_DIV_EXPR, orig_op0=0xb7cec528, orig_op1=0xb7cec720, convert_p=1) at /home/richard/src/gcc-4_1-branch/gcc/cp/typeck.c:3594 #6 0x080576d7 in build_new_op (code=TRUNC_DIV_EXPR, flags=3, arg1=0xb7cec528, arg2=0xb7cec720, arg3=0x0, overloaded_p=0xbfc21583 "") at /home/richard/src/gcc-4_1-branch/gcc/cp/call.c:3914 #7 0x08188321 in build_x_binary_op (code=TRUNC_DIV_EXPR, arg1=0xb7cec528, arg2=0xb7cec720, overloaded_p=0xbfc21583 "") at /home/richard/src/gcc-4_1-branch/gcc/cp/typeck.c:2778 Indeed a C++ frontend issue and a regression from 3.4.
Closing 4.1 branch.