[Bug c/56607] New: [4.8 regression] GCC fails to warn on division by zero

ppluzhnikov at google dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 12 22:44:00 GMT 2013


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



More information about the Gcc-bugs mailing list