diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-27 19:23:46 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-27 19:23:46 +0000 |
commit | 0a0395125e1f619c73c0d0c754c630cd92cc4aa7 (patch) | |
tree | e82f0518b7effbc1ef6747e290fab76ed9d1f179 | |
parent | 04ed2c7147286ab11c8ba25e486e3f726c4970d4 (diff) |
PR c++/49165
* c-common.c (c_common_truthvalue_conversion) <case COND_EXPR>: For
C++ don't call c_common_truthvalue_conversion on void type arms.
* g++.dg/eh/cond6.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@174351 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/eh/cond6.C | 43 |
4 files changed, 62 insertions, 7 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index d2961f36a35..09a1fbcc17c 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2011-05-27 Jakub Jelinek <jakub@redhat.com> + + PR c++/49165 + * c-common.c (c_common_truthvalue_conversion) <case COND_EXPR>: For + C++ don't call c_common_truthvalue_conversion on void type arms. + 2011-04-19 Richard Guenther <rguenther@suse.de> PR preprocessor/48248 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 0be399641d5..ea5a196d14d 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -3915,14 +3915,15 @@ 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); + /* 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 97e651d871f..e1f9726f0a5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-05-27 Jakub Jelinek <jakub@redhat.com> + + PR c++/49165 + * g++.dg/eh/cond6.C: New test. + 2011-05-27 Jason Merrill <jason@redhat.com> * g++.dg/template/const5.C: New. diff --git a/gcc/testsuite/g++.dg/eh/cond6.C b/gcc/testsuite/g++.dg/eh/cond6.C new file mode 100644 index 00000000000..1eed63ec84f --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/cond6.C @@ -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 (); + } +} |