From 1104b28bc84483a6e98335cc5369d089a56ec6ed Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Tue, 7 Feb 2006 19:41:14 +0000 Subject: c.opt: C++ frontend supports -Wdiv-by-zero. 2006-02-07 Dirk Mueller * c.opt: C++ frontend supports -Wdiv-by-zero. * c-opts.c (c_common_handle_option): Remove dead case. * typeck.c (build_binary_op): Annotate div-by-zero warnings to make -Wno-div-by-zero have an effect. g++.dg/warn/Wdiv-by-zero.C: New test. g++.dg/warn/Wno-div-by-zero.C: New. From-SVN: r110712 --- gcc/ChangeLog | 5 +++++ gcc/c-opts.c | 4 ---- gcc/c.opt | 2 +- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck.c | 8 ++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C | 7 +++++++ gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C | 8 ++++++++ 8 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C create mode 100644 gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e11fb2..4946e3b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2006-02-07 Dirk Mueller + + * c.opt: C++ frontend supports -Wdiv-by-zero. + * c-opts.c (c_common_handle_option): Remove dead case. + 2006-02-07 Eric Botcazou * configure.ac (TLS assembler check): Do not enable TLS by diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 8c5827a..34fc6b9 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -431,10 +431,6 @@ c_common_handle_option (size_t scode, const char *arg, int value) cpp_opts->warn_deprecated = value; break; - case OPT_Wdiv_by_zero: - warn_div_by_zero = value; - break; - case OPT_Wendif_labels: cpp_opts->warn_endif_labels = value; break; diff --git a/gcc/c.opt b/gcc/c.opt index 4ce9b9f..a841d52 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -166,7 +166,7 @@ C++ ObjC++ Var(warn_deprecated) Init(1) Warn about deprecated compiler features Wdiv-by-zero -C ObjC Var(warn_div_by_zero) Init(1) +C ObjC C++ Var(warn_div_by_zero) Init(1) Warn about compile-time integer division by zero Weffc++ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cdfeaf3..8b0e9fc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2006-02-07 Dirk Mueller + + * typeck.c (build_binary_op): Annotate div-by-zero + warnings to make -Wno-div-by-zero have an effect. + 2006-02-07 Mark Mitchell PR c++/9737 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 1fb3cbf..adac227 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2954,9 +2954,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)) { if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1)) - warning (0, "division by zero in %<%E / 0%>", op0); + warning (OPT_Wdiv_by_zero, "division by zero in %<%E / 0%>", op0); else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1)) - warning (0, "division by zero in %<%E / 0.%>", op0); + warning (OPT_Wdiv_by_zero, "division by zero in %<%E / 0.%>", op0); if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) code0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0))); @@ -2991,9 +2991,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, case TRUNC_MOD_EXPR: case FLOOR_MOD_EXPR: if (code1 == INTEGER_TYPE && integer_zerop (op1)) - warning (0, "division by zero in %<%E %% 0%>", op0); + warning (OPT_Wdiv_by_zero, "division by zero in %<%E %% 0%>", op0); else if (code1 == REAL_TYPE && real_zerop (op1)) - warning (0, "division by zero in %<%E %% 0.%>", op0); + warning (OPT_Wdiv_by_zero, "division by zero in %<%E %% 0.%>", op0); if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9e44af..e9fb7d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-02-07 Dirk Mueller + + g++.dg/warn/Wdiv-by-zero.C: New test. + g++.dg/warn/Wno-div-by-zero.C: New. + 2006-02-07 Jeff Law * gcc.dg/tree-ssa/vrp01.c: Update dumpfile names now that we have diff --git a/gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C b/gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C new file mode 100644 index 0000000..7dc7766 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C @@ -0,0 +1,7 @@ +// test that division by zero warnings are enabled by default +int breakme() +{ + int x = 0; + x /= 0; // { dg-warning "division by" } + return x; +} diff --git a/gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C b/gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C new file mode 100644 index 0000000..937628e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C @@ -0,0 +1,8 @@ +// { dg-options "-Wno-div-by-zero" } + +int breakme() +{ + int x = 0; + x /= 0; + return x; +} -- cgit v1.1