aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2012-03-12 19:29:38 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2012-03-12 19:29:38 +0000
commit7792bd8a9001f514e3b05d2c6d9e0813e8ef7d8e (patch)
tree4ee764061107dc0a9f733319c450c3d19c7e9dfa /gcc
parenta029a1543541b5231e2b7eba3ef1b30046234d36 (diff)
downloadgcc-7792bd8a9001f514e3b05d2c6d9e0813e8ef7d8e.zip
gcc-7792bd8a9001f514e3b05d2c6d9e0813e8ef7d8e.tar.gz
gcc-7792bd8a9001f514e3b05d2c6d9e0813e8ef7d8e.tar.bz2
re PR c++/52299 (GCC warns on compile time division by zero erroneously)
/cp 2012-03-12 Paolo Carlini <paolo.carlini@oracle.com> PR c++/52299 * pt.c (tsubst_copy_and_build, case COND_EXPR): Avoid bogus division by zero warnings. /testsuite 2012-03-12 Paolo Carlini <paolo.carlini@oracle.com> PR c++/52299 * g++.dg/warn/Wdiv-by-zero-bogus.C: New. From-SVN: r185264
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c34
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/warn/Wdiv-by-zero-bogus.C30
4 files changed, 71 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 24e629f..1a3ac83 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2012-03-12 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/52299
+ * pt.c (tsubst_copy_and_build, case COND_EXPR): Avoid bogus
+ division by zero warnings.
+
2012-03-08 Paolo Carlini <paolo.carlini@oracle.com>
* typeck.c (build_array_ref, cp_build_addr_expr_1, convert_ptrmem,
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4980c19..54d540d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13943,11 +13943,35 @@ tsubst_copy_and_build (tree t,
}
case COND_EXPR:
- return build_x_conditional_expr
- (RECUR (TREE_OPERAND (t, 0)),
- RECUR (TREE_OPERAND (t, 1)),
- RECUR (TREE_OPERAND (t, 2)),
- complain);
+ {
+ tree cond = RECUR (TREE_OPERAND (t, 0));
+ tree exp1, exp2;
+
+ if (TREE_CODE (cond) == INTEGER_CST)
+ {
+ if (integer_zerop (cond))
+ {
+ ++c_inhibit_evaluation_warnings;
+ exp1 = RECUR (TREE_OPERAND (t, 1));
+ --c_inhibit_evaluation_warnings;
+ exp2 = RECUR (TREE_OPERAND (t, 2));
+ }
+ else
+ {
+ exp1 = RECUR (TREE_OPERAND (t, 1));
+ ++c_inhibit_evaluation_warnings;
+ exp2 = RECUR (TREE_OPERAND (t, 2));
+ --c_inhibit_evaluation_warnings;
+ }
+ }
+ else
+ {
+ exp1 = RECUR (TREE_OPERAND (t, 1));
+ exp2 = RECUR (TREE_OPERAND (t, 2));
+ }
+
+ return build_x_conditional_expr (cond, exp1, exp2, complain);
+ }
case PSEUDO_DTOR_EXPR:
return finish_pseudo_destructor_expr
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 130a23f..90b1197 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-03-12 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/52299
+ * g++.dg/warn/Wdiv-by-zero-bogus.C: New.
+
2012-03-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
PR tree-optimization/46728
@@ -18,7 +23,7 @@
* gcc.target/avr/torture/addr-space-0.h: New test.
* gcc.target/avr/torture/addr-space-1.h: New test.
* gcc.target/avr/torture/addr-space-x.h: New test.
-
+
2012-03-12 Andrew Pinski <apinski@cavium.com>
* gcc.dg/tree-ssa/phi-opt-7.c: New testcase.
diff --git a/gcc/testsuite/g++.dg/warn/Wdiv-by-zero-bogus.C b/gcc/testsuite/g++.dg/warn/Wdiv-by-zero-bogus.C
new file mode 100644
index 0000000..2157df3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wdiv-by-zero-bogus.C
@@ -0,0 +1,30 @@
+// PR c++/52299
+
+template<unsigned x>
+struct test0 {
+ static const unsigned a_
+ = x ? 10 / x : 10;
+};
+
+template<unsigned x>
+struct test1 {
+ static const unsigned a_
+ = !x ? 10 : 10 / x;
+};
+
+template<bool x>
+struct test2 {
+ static const unsigned a_
+ = x ? 10 / x : 10;
+};
+
+template<bool x>
+struct test3 {
+ static const unsigned a_
+ = !x ? 10 : 10 / x;
+};
+
+unsigned i0 = test0<0>::a_;
+unsigned i1 = test1<0>::a_;
+unsigned i2 = test2<false>::a_;
+unsigned i3 = test3<false>::a_;