aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/pr56607.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2013-03-16 20:35:41 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2013-03-16 20:35:41 +0100
commit87eb16a1bc6cb76e3078d93ba068a35aaa487279 (patch)
treec5829e1acd56f9bb7299a43348de50278b005d68 /gcc/testsuite/c-c++-common/pr56607.c
parent9a54d96aabdc4501573aa0cd2f5201a206963f69 (diff)
downloadgcc-87eb16a1bc6cb76e3078d93ba068a35aaa487279.zip
gcc-87eb16a1bc6cb76e3078d93ba068a35aaa487279.tar.gz
gcc-87eb16a1bc6cb76e3078d93ba068a35aaa487279.tar.bz2
re PR c++/56607 (GCC fails to warn on division by zero)
PR c++/56607 * typeck.c (cp_build_binary_op): When calling warn_for_div_by_zero, pass op1 through maybe_constant_value first. * g++.dg/warn/Wdiv-by-zero-2.C: New test. * c-c++-common/pr56607.c: New test. From-SVN: r196704
Diffstat (limited to 'gcc/testsuite/c-c++-common/pr56607.c')
-rw-r--r--gcc/testsuite/c-c++-common/pr56607.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/pr56607.c b/gcc/testsuite/c-c++-common/pr56607.c
new file mode 100644
index 0000000..d7faa81
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr56607.c
@@ -0,0 +1,29 @@
+/* PR c++/56607 */
+/* { dg-do compile { target { { lp64 || ilp32 } || llp64 } } } */
+/* { dg-options "-O2 -Wdiv-by-zero" } */
+
+int
+f1 (void)
+{
+ return 1 / (sizeof (char) - 1); /* { dg-warning "division by zero" } */
+}
+
+int
+f2 (void)
+{
+ const int x = sizeof (char) - 1;
+ return 1 / x; /* { dg-warning "division by zero" "" { target c++ } } */
+}
+
+int
+f3 (void)
+{
+ return 1 / (sizeof (int) / 3 - 1); /* { dg-warning "division by zero" } */
+}
+
+int
+f4 (void)
+{
+ const int x = sizeof (int) / 3 - 1;
+ return 1 / x; /* { dg-warning "division by zero" "" { target c++ } } */
+}