This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gcc] no warning on int conversion overflow in non-c99 mode


On 2014-02-18 12:09:52 +0800, Chung-Ju Wu wrote:
> But to my understanding, the warning comes from that you didn't explicitly
> tell the constant type, nor cast it into an representable value for lvalue.
> So gcc warns you:
>   "Hey, there is an implicit constant type, and I am going to convert it
>    into a signed int.  Be careful that there is an overflow!!"

But it currently behaves in an inconsistent way: without -pedantic,
it signals some overflows, but not all of them.

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

> If you use either
>     signed int ia = 2166136261u;
>     signed int ia1 = 2147483648u;
> or
>     signed int ia = (signed int) 2166136261;
>     signed int ia1 = (signed int) 2147483648;
> 
> There is no warning message because it makes gcc understand
> that you know what exactly you are doing.

I don't think this is necessarily the case. You could have code like:

#define VAL 2166136261u;

  unsigned int i = VAL * VAL;

  /* ... */

  int ia = VAL;

where some value is used at various places in the code, and the
user doesn't remember that VAL doesn't fit in an int or forgot the
"unsigned". The unsigned type could have been given because it is
needed in some places like in VAL * VAL above (to have modular
arithmetic).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]