diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e11fb278db..4946e3b05c8 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 8c5827a3959..34fc6b9b0ad 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 4ce9b9fed89..a841d528132 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 cdfeaf33d1e..8b0e9fc444b 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 1fb3cbf7915..adac22716fb 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 c9e44af3d86..e9fb7d1b616 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 00000000000..7dc77667c22 --- /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 00000000000..937628ee924 --- /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; +}