This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/17645] Add a warning for potentially unsafe unsigned operations
- From: "mathieu at malaterre dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2005 02:59:47 -0000
- Subject: [Bug c++/17645] Add a warning for potentially unsafe unsigned operations
- References: <20040924041536.17645.mathieu@malaterre.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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 <iostream>
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