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: [email protected]
ReportedBy: [email protected]
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