public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/56607] New: [4.8 regression] GCC fails to warn on division by zero
@ 2013-03-12 22:44 ppluzhnikov at google dot com
  2013-03-13  8:27 ` [Bug c++/56607] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2013-03-12 22:44 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56607
           Summary: [4.8 regression] GCC fails to warn on division by zero
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ppluzhnikov@google.com


Test:

typedef unsigned long size_t;

#ifdef TEST1
int ShouldntCompile ()
{
  return 1 / ((sizeof(int) / 3) - 1);
}
#endif

#ifdef TEST2
int WontCompile ()
{
  const int x = (sizeof(int) / 3) - 1;
  return 1 / x;
}
#endif

Using gcc-4.7:
gcc -Werror -c -DTEST1 as.c ; echo $?

as.c: In function 'ShouldntCompile':
as.c:6:12: error: division by zero [-Werror=div-by-zero]
cc1: all warnings being treated as errors
1

g++ -Werror -c -DTEST1 as.c ; echo $?
# same as above

gcc -Werror -c -DTEST2 as.c ; echo $?
0   # problem

g++ -Werror -c -DTEST2 as.c ; echo $?

as.c: In function 'int WontCompile()':
as.c:14:14: error: division by zero [-Werror=div-by-zero]
cc1plus: all warnings being treated as errors
1


Using gcc-4.8 (r196619):


gcc -Werror -c -DTEST1 as.c; echo $?

as.c: In function 'ShouldntCompile':
as.c:6:12: error: division by zero [-Werror=div-by-zero]
   return 1 / ((sizeof(int) / 3) - 1);
            ^
cc1: all warnings being treated as errors
1


g++ -Werror -c -DTEST1 as.c; echo $?
0  # 4.8 regression, used to warn.


gcc -Werror -c -DTEST2 as.c ; echo $?
0   # still a problem


g++ -Werror -c -DTEST2 as.c; echo $?

as.c: In function 'int WontCompile()':
as.c:14:14: error: division by zero [-Werror=div-by-zero]
   return 1 / x;
              ^
cc1plus: all warnings being treated as errors
1


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

end of thread, other threads:[~2013-03-22 15:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-12 22:44 [Bug c/56607] New: [4.8 regression] GCC fails to warn on division by zero ppluzhnikov at google dot com
2013-03-13  8:27 ` [Bug c++/56607] " jakub at gcc dot gnu.org
2013-03-13  8:35 ` jakub at gcc dot gnu.org
2013-03-13  9:50 ` rguenth at gcc dot gnu.org
2013-03-13 14:19 ` jason at gcc dot gnu.org
2013-03-16 19:36 ` [Bug c++/56607] [4.8/4.9 " jakub at gcc dot gnu.org
2013-03-22 15:59 ` jakub at gcc dot gnu.org
2013-03-22 15:59 ` jakub 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).