Delay folding of bool conversion into COND_EXPR.
gcc/c-family/ * c-common.c (c_common_truthvalue_conversion): Don't distribute into COND_EXPR in C++. gcc/cp/ * cp-gimplify.c (cp_fold): Distribute cp_truthvalue_conversion into COND_EXPR. From-SVN: r240893
This commit is contained in:
parent
490a67336b
commit
627be19fe1
|
@ -1,3 +1,8 @@
|
|||
2016-10-08 Jason Merrill <jason@redhat.com>
|
||||
|
||||
* c-common.c (c_common_truthvalue_conversion): Don't distribute
|
||||
into COND_EXPR in C++.
|
||||
|
||||
2016-10-08 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* c-lex.c (c_lex_with_flags) <case CPP_COMMENT>: For CPP_COMMENT
|
||||
|
|
|
@ -4694,21 +4694,8 @@ c_common_truthvalue_conversion (location_t location, tree expr)
|
|||
}
|
||||
/* Distribute the conversion into the arms of a COND_EXPR. */
|
||||
if (c_dialect_cxx ())
|
||||
{
|
||||
tree op1 = TREE_OPERAND (expr, 1);
|
||||
tree op2 = TREE_OPERAND (expr, 2);
|
||||
int w = warn_int_in_bool_context;
|
||||
warn_int_in_bool_context = 0;
|
||||
/* In C++ one of the arms might have void type if it is throw. */
|
||||
if (!VOID_TYPE_P (TREE_TYPE (op1)))
|
||||
op1 = c_common_truthvalue_conversion (location, op1);
|
||||
if (!VOID_TYPE_P (TREE_TYPE (op2)))
|
||||
op2 = c_common_truthvalue_conversion (location, op2);
|
||||
expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node,
|
||||
TREE_OPERAND (expr, 0), op1, op2);
|
||||
warn_int_in_bool_context = w;
|
||||
goto ret;
|
||||
}
|
||||
/* Avoid premature folding. */
|
||||
break;
|
||||
else
|
||||
{
|
||||
int w = warn_int_in_bool_context;
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2016-10-08 Jason Merrill <jason@redhat.com>
|
||||
|
||||
* cp-gimplify.c (cp_fold): Distribute cp_truthvalue_conversion
|
||||
into COND_EXPR.
|
||||
|
||||
2016-10-07 Jason Merrill <jason@redhat.com>
|
||||
|
||||
Further P0135 refinement.
|
||||
|
|
|
@ -2253,6 +2253,15 @@ cp_fold (tree x)
|
|||
op1 = cp_fold (TREE_OPERAND (x, 1));
|
||||
op2 = cp_fold (TREE_OPERAND (x, 2));
|
||||
|
||||
if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE)
|
||||
{
|
||||
warning_sentinel (warn_int_in_bool_context);
|
||||
if (!VOID_TYPE_P (TREE_TYPE (op1)))
|
||||
op1 = cp_truthvalue_conversion (op1);
|
||||
if (!VOID_TYPE_P (TREE_TYPE (op2)))
|
||||
op2 = cp_truthvalue_conversion (op2);
|
||||
}
|
||||
|
||||
if (op0 != TREE_OPERAND (x, 0)
|
||||
|| op1 != TREE_OPERAND (x, 1)
|
||||
|| op2 != TREE_OPERAND (x, 2))
|
||||
|
|
Loading…
Reference in New Issue