public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59753] New: Missing -Woverflow warning with signed constant conversion between T_MAX+1 and UT_MAX
@ 2014-01-10 10:19 vincent-gcc at vinc17 dot net
  2014-02-05 10:49 ` [Bug c/59753] " mpolacek at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2014-01-10 10:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59753
           Summary: Missing -Woverflow warning with signed constant
                    conversion between T_MAX+1 and UT_MAX
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net

When writing "int d = some_signed_constant;", one expects a -Woverflow warning
if some_signed_constant > INT_MAX, but one actually gets a warning only if
some_signed_constant > UINT_MAX. Similarly for other types, such as char and
short.

For instance, with the following program, one expects 6 warnings, but one only
gets 2.

#include <stdio.h>
int main (void)
{
  short a = 32768;
  short b = 65535;
  short c = 65536;
  int d = 2147483648;
  int e = 4294967295;
  int f = 4294967296;
  printf ("%d %d %d %d %d %d\n", a, b, c, d, e, f);
  return 0;
}

$ gcc-snapshot tst.c -o tst
tst.c: In function 'main':
tst.c:6:3: warning: overflow in implicit constant conversion [-Woverflow]
   short c = 65536;
   ^
tst.c:9:3: warning: overflow in implicit constant conversion [-Woverflow]
   int f = 4294967296;
   ^

This occurs with:
gcc (Debian 20131201-1) 4.9.0 20131201 (experimental) [trunk revision 205573]
and older versions (4.7 and 4.8 at least).


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-05 17:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-10 10:19 [Bug c/59753] New: Missing -Woverflow warning with signed constant conversion between T_MAX+1 and UT_MAX vincent-gcc at vinc17 dot net
2014-02-05 10:49 ` [Bug c/59753] " mpolacek at gcc dot gnu.org
2014-02-05 11:40 ` vincent-gcc at vinc17 dot net
2014-02-05 15:51 ` mpolacek at gcc dot gnu.org
2014-02-05 16:40 ` [Bug c/59753] -Woverflow warning inconsistency with signed constant conversion between T_MAX+1 and UT_MAX vs larger than UT_MAX vincent-gcc at vinc17 dot net
2014-02-05 16:47 ` manu at gcc dot gnu.org
2014-02-05 17:31 ` vincent-gcc at vinc17 dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).