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