http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54288

             Bug #: 54288
           Summary: Wrong sign compiled at run-time
    Classification: Unclassified
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: l.lapoi...@srtechlabs.com


Simple code will be found below.
Optimization of the code lose the sign of a negative integer.


#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <iostream.h>


struct struct_sz
{
   static const unsigned int scu_sz = 40;
};


class CQ
{
public:
void  doIt();
      CQ();
private:
   int _i;
   bool question();
};
//--------------------
const unsigned int struct_sz::scu_sz;

CQ::CQ()
{
   _i = -1;
}

void CQ::doIt()
{
   double dZ;
   double dO = 0.0;
   if (question())
   {
      dO = 1.0;
   }
   else
   {
      //Execution is going here

      dO = 0.0;
   }
   dZ = 1.0/dO;
   cout << dZ << endl;
}

bool CQ::question()
{
   if (_i < struct_sz::scu_sz - 2)
   {
      return true;
   }
   return false;
}


int main(int argc, char* argv[])
{
   CQ cq;
   cq.doIt();
  return 0;
}

Reply via email to