g++ crashes when compiling not-so-intricate source file

Bug #155259 reported by Nicolas Maquet
2
Affects Status Importance Assigned to Milestone
gcc-4.1 (Ubuntu)
Fix Released
Undecided
Matthias Klose

Bug Description

Binary package hint: g++-4.1

Here is the source-code that exposes the bug :

/***************************************/

#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;
}

/***************************************/

And here's the output :

nmaquet@nmaquet-desktop:/tmp$ g++ bug.cpp
bug.cpp: In function ‘double arctan(double)’:
bug.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/ccgAvvVR.out file, please attach this to your bugreport.

Revision history for this message
Nicolas Maquet (nmaquet) wrote :

This bug was collected during a 1st year CS Bachelor course.

Revision history for this message
Nicolas Maquet (nmaquet) wrote :

The bug was first discovered during a programming session on Dapper but it is reproducible on an up-to-date Gutsy.

Revision history for this message
Matthias Klose (doko) wrote :

closing this as fixed (in g++-4.2, which is the default in hardy). The code itself is invalid:

$ g++-4.2 -c t.cc
t.cc: In function 'double arctan(double)':
t.cc:12: error: cannot convert 'double __complex__' to 'double' in assignment

Changed in gcc-4.1:
assignee: nobody → doko
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.