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:
parent
a029a15435
commit
7792bd8a90
|
@ -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>
|
2012-03-08 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
* typeck.c (build_array_ref, cp_build_addr_expr_1, convert_ptrmem,
|
* typeck.c (build_array_ref, cp_build_addr_expr_1, convert_ptrmem,
|
||||||
|
|
34
gcc/cp/pt.c
34
gcc/cp/pt.c
|
@ -13943,11 +13943,35 @@ tsubst_copy_and_build (tree t,
|
||||||
}
|
}
|
||||||
|
|
||||||
case COND_EXPR:
|
case COND_EXPR:
|
||||||
return build_x_conditional_expr
|
{
|
||||||
(RECUR (TREE_OPERAND (t, 0)),
|
tree cond = RECUR (TREE_OPERAND (t, 0));
|
||||||
RECUR (TREE_OPERAND (t, 1)),
|
tree exp1, exp2;
|
||||||
RECUR (TREE_OPERAND (t, 2)),
|
|
||||||
complain);
|
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:
|
case PSEUDO_DTOR_EXPR:
|
||||||
return finish_pseudo_destructor_expr
|
return finish_pseudo_destructor_expr
|
||||||
|
|
|
@ -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>
|
2012-03-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
|
||||||
|
|
||||||
PR tree-optimization/46728
|
PR tree-optimization/46728
|
||||||
|
|
|
@ -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_;
|
Loading…
Reference in New Issue