[Bug c/17645] Add a warning for potentially unsafe unsigned operations

2006-08-07 Thread mathieu at malaterre dot com


--- Comment #11 from mathieu at malaterre dot com  2006-08-07 20:25 ---
Tested today (Aug 7, 2006) with:
$ /usr/lib/gcc-snapshot/bin/g++ --version  
   /tmp
g++ (GCC) 4.2.0 20060721 (experimental)
Copyright (C) 2006 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.

$ /usr/lib/gcc-snapshot/bin/g++ -Wall -ftrapv bla.cxx
$ ./a.out   
[1]24229 abort  ./a.out


Marking the bug fixed. Thank you !


-- 

mathieu at malaterre dot com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||FIXED


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



[Bug c++/17645] Add a warning for potentially unsafe unsigned operations

2005-07-05 Thread mathieu at malaterre dot com

--- Additional Comments From mathieu at malaterre dot com  2005-07-06 02:32 
---
Using gcc --version:
g++ (GCC) 4.1.0 20050607 (experimental)

I still cannot get anything using the -ftrapv:

Ex is:

#include 

int main()
{
  const unsigned int a = 11;
  const unsigned int b = 10;
  const double t = 0.5;
  const unsigned int c = a + t * (b -a);
  std::cout << "c=" << c << std::endl;
  const unsigned int d = (1.0 - t) * a + t * b;
  std::cout << "d=" << d << std::endl;

  return 0;
}


compile line:

$ /usr/lib/gcc-snapshot/bin/g++ -O3 -ftrapv test.c

$ ./a.out
c=2147483658
d=10

It looks like -ftrapv only works on signed overflow.

-- 


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


[Bug c++/17645] Add a warning for potentially unsafe unsigned operations

2005-07-05 Thread mathieu at malaterre dot com

--- Additional Comments From mathieu at malaterre dot com  2005-07-06 02:59 
---
Using gcc --version:
g++ (GCC) 4.1.0 20050607 (experimental)

I can still reproduce the same unsafe operation:

#include 

int main()
{
  unsigned int l = (unsigned int)-1;
  const int a = l/2;
  const int b = l/2+1;
  const double t = 0.5;
  const int c = a + t * (b -a);
  std::cout << "c=" << c << std::endl;
  const int d = (1.0 - t) * a + t * b;
  std::cout << "d=" << d << std::endl;

  return 0;
}

$ /usr/lib/gcc-snapshot/bin/g++ -O3 -ftrapv test.c
$  ./a.out 
   
c=2147483647
d=0


I cannot seems to find a way to generate traps on overflow.

-- 
   What|Removed |Added

  Component|c   |c++


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


[Bug c/17645] Add a warning for potentially unsafe unsigned operations

2005-07-05 Thread mathieu at malaterre dot com

--- Additional Comments From mathieu at malaterre dot com  2005-07-06 03:00 
---
Using gcc --version:
g++ (GCC) 4.1.0 20050607 (experimental)

I can still reproduce the same unsafe operation:

#include 

int main()
{
  unsigned int l = (unsigned int)-1;
  const int a = l/2;
  const int b = l/2+1;
  const double t = 0.5;
  const int c = a + t * (b -a);
  std::cout << "c=" << c << std::endl;
  const int d = (1.0 - t) * a + t * b;
  std::cout << "d=" << d << std::endl;

  return 0;
}

$ /usr/lib/gcc-snapshot/bin/g++ -O3 -ftrapv test.c
$  ./a.out 
   
c=2147483647
d=0


I cannot seems to find a way to generate traps on overflow.

-- 
   What|Removed |Added

  Component|c++ |c


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