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
This commit is contained in:
Paolo Carlini 2012-03-12 19:29:38 +00:00 committed by Paolo Carlini
parent a029a15435
commit 7792bd8a90
4 changed files with 71 additions and 6 deletions

View File

@ -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,

View File

@ -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

View File

@ -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.

View File

@ -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_;