public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/55715] New: bogus overflow warning for #if A-B when A<0 & B==minimum integer
@ 2012-12-17  7:23 eggert at gnu dot org
  2013-12-10  1:23 ` [Bug preprocessor/55715] " jsm28 at gcc dot gnu.org
  2013-12-10  1:25 ` jsm28 at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: eggert at gnu dot org @ 2012-12-17  7:23 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55715
           Summary: bogus overflow warning for #if A-B when A<0 &
                    B==minimum integer
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eggert@gnu.org


Consider this C program:

#if 9223372036854775807 < 0
#endif
#if -1 - 9223372036854775807 < 0
#endif
#if -1 - (-1 - 9223372036854775807) < 0
#endif

When compiled with GCC (x86-64), GCC 4.7.2 warns:

t.c:5:37: warning: integer overflow in preprocessor expression [enabled by
default]

The warning is incorrect, since there is no overflow in this program.

Evidently GCC's preprocessor computes A-B by first negating B, and then adding
the result to A.  This causes GCC to incorrectly report overflow when B is the
minimum possible integer and A is negative, because in this case -B overflows
even though A-B does not overflow.


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

end of thread, other threads:[~2013-12-10  1:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-17  7:23 [Bug preprocessor/55715] New: bogus overflow warning for #if A-B when A<0 & B==minimum integer eggert at gnu dot org
2013-12-10  1:23 ` [Bug preprocessor/55715] " jsm28 at gcc dot gnu.org
2013-12-10  1:25 ` jsm28 at gcc dot gnu.org

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).