summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2009-06-30 22:04:36 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2009-06-30 22:04:36 +0000
commit57d0100fbd6823e5c9715d3f46030484a7667371 (patch)
tree22d4472aed1465f326e3cc594adf1560e23c69d9
parentc899341f16da17859b9a36a8839ce1c49d7420df (diff)
downloadgcc-57d0100fbd6823e5c9715d3f46030484a7667371.tar.gz
PR c++/40566
* convert.c (convert_to_integer) <case COND_EXPR>: Don't convert to type arguments that have void type. * g++.dg/parse/cond5.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149121 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/convert.c12
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/cond5.C10
4 files changed, 28 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1b13273ded3..8d0688bcabe 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
2009-06-30 Jakub Jelinek <jakub@redhat.com>
+ PR c++/40566
+ * convert.c (convert_to_integer) <case COND_EXPR>: Don't convert
+ to type arguments that have void type.
+
PR debug/40573
* dwarf2out.c (gen_formal_parameter_die): Call
equate_decl_number_to_die if node is different from origin.
diff --git a/gcc/convert.c b/gcc/convert.c
index 8245e1647fb..706dc41985c 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -772,10 +772,16 @@ convert_to_integer (tree type, tree expr)
case COND_EXPR:
/* It is sometimes worthwhile to push the narrowing down through
- the conditional and never loses. */
+ the conditional and never loses. A COND_EXPR may have a throw
+ as one operand, which then has void type. Just leave void
+ operands as they are. */
return fold_build3 (COND_EXPR, type, TREE_OPERAND (expr, 0),
- convert (type, TREE_OPERAND (expr, 1)),
- convert (type, TREE_OPERAND (expr, 2)));
+ VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 1)))
+ ? TREE_OPERAND (expr, 1)
+ : convert (type, TREE_OPERAND (expr, 1)),
+ VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 2)))
+ ? TREE_OPERAND (expr, 2)
+ : convert (type, TREE_OPERAND (expr, 2)));
default:
break;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ebdf6018833..513a973da1e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-06-30 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/40566
+ * g++.dg/parse/cond5.C: New test.
+
2009-06-30 Nathan Froyd <froydnj@codesourcery.com>
* gcc.dg/tree-ssa/gen-vect-25.c (n): New variable.
diff --git a/gcc/testsuite/g++.dg/parse/cond5.C b/gcc/testsuite/g++.dg/parse/cond5.C
new file mode 100644
index 00000000000..7ed9fbe892e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/cond5.C
@@ -0,0 +1,10 @@
+// PR c++/40566
+
+void
+f (int x, int y)
+{
+ int c = x ? 23 : throw "bla";
+ short d = y ? throw "bla" : 23;
+ char e = x ? 23 : throw "bla";
+ long f = x ? 23 : throw "bla";
+}