aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/divbyzero.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-10-23 18:14:31 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-10-23 18:14:31 +0000
commit6c36d76bf6521dd1cc09b8d7e379a02d138ffd53 (patch)
treea86518d1f2373ba547d08bd0867d006b5db75f24 /gcc/testsuite/gcc.dg/divbyzero.c
parent28a8851e654560d565e7270812ea1b2e1c33b14d (diff)
downloadgcc-6c36d76bf6521dd1cc09b8d7e379a02d138ffd53.zip
gcc-6c36d76bf6521dd1cc09b8d7e379a02d138ffd53.tar.gz
gcc-6c36d76bf6521dd1cc09b8d7e379a02d138ffd53.tar.bz2
c-common.c (warn_div_by_zero): New.
* c-common.c (warn_div_by_zero): New. * c-common.h (warn_div_by_zero): New. * c-decl.c (c_decode_option): Take it on the command line. * c-typeck.c (build_binary_op): Warn about division by zero. * doc/invoke.texi: Document the new command line option, fix documentation of -Wmultichar. * testsuite/gcc.dg/divbyzero.c: New tests. * testsuite/gcc.dg/noncompile/20010524-1.c: Update. From-SVN: r46439
Diffstat (limited to 'gcc/testsuite/gcc.dg/divbyzero.c')
-rw-r--r--gcc/testsuite/gcc.dg/divbyzero.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/divbyzero.c b/gcc/testsuite/gcc.dg/divbyzero.c
new file mode 100644
index 0000000..607aa12
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divbyzero.c
@@ -0,0 +1,21 @@
+/* Copyright (C) 2001 Free Software Foundation, Inc. */
+
+/* { dg-do compile } */
+
+/* Source: Neil Booth, Oct 22 2001. PR 150 - warn about division by
+ zero. */
+
+#define ZERO (4 - 6 + 2)
+
+int main (int argc, char *argv[])
+{
+ int w = argc % ZERO; /* { dg-warning "division by zero" } */
+ int x = argc / 0; /* { dg-warning "division by zero" } */
+ int y = argc / ZERO; /* { dg-warning "division by zero" } */
+
+ double z = 0.0 / 0.0 ; /* { dg-bogus "division by zero" } */
+ w = (ZERO ? y / ZERO : x); /* { dg-bogus "division by zero" } */
+ x = (ZERO ? argc % ZERO: x); /* { dg-bogus "division by zero" } */
+
+ return 0;
+}