@@ -3942,14 +3942,15 @@ c_common_truthvalue_conversion (location
/* 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);
+ /* 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),
- c_common_truthvalue_conversion (location,
- TREE_OPERAND (expr,
- 1)),
- c_common_truthvalue_conversion (location,
- TREE_OPERAND (expr,
- 2)));
+ TREE_OPERAND (expr, 0), op1, op2);
goto ret;
}
else
@@ -0,0 +1,43 @@
+// PR c++/49165
+// { dg-do run }
+
+extern "C" void abort ();
+
+int
+foo (bool x, int y)
+{
+ if (y < 10 && (x ? 1 : throw 1))
+ y++;
+ if (y > 20 || (x ? 1 : throw 2))
+ y++;
+ return y;
+}
+
+int
+main ()
+{
+ if (foo (true, 0) != 2
+ || foo (true, 10) != 11
+ || foo (false, 30) != 31)
+ abort ();
+ try
+ {
+ foo (false, 0);
+ abort ();
+ }
+ catch (int i)
+ {
+ if (i != 1)
+ abort ();
+ }
+ try
+ {
+ foo (false, 10);
+ abort ();
+ }
+ catch (int i)
+ {
+ if (i != 2)
+ abort ();
+ }
+}