From 6f35ff1bb1b76f131dc4e9b49750adeb04770ff1 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Fri, 10 Jul 2009 16:02:59 +0000 Subject: [PATCH] backport: re PR c++/40566 (rejects promoted throw) 2009-07-10 Richard Guenther Backport from mainline 2009-06-30 Jakub Jelinek PR c++/40566 * convert.c (convert_to_integer) : Don't convert to type arguments that have void type. * g++.dg/parse/cond5.C: New test. From-SVN: r149488 --- gcc/ChangeLog | 9 +++++++++ gcc/convert.c | 12 +++++++++--- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/g++.dg/parse/cond5.C | 10 ++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/cond5.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 282148ea546f..18de990737bb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2009-07-10 Richard Guenther + + Backport from mainline + 2009-06-30 Jakub Jelinek + + PR c++/40566 + * convert.c (convert_to_integer) : Don't convert + to type arguments that have void type. + 2009-07-10 Richard Guenther Backport from mainline diff --git a/gcc/convert.c b/gcc/convert.c index d5de95c1b46c..84d4ec7653ea 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -733,10 +733,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 b3cc101ee35b..125bb87ac1de 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2009-07-10 Richard Guenther + + Backport from mainline + 2009-06-30 Jakub Jelinek + + PR c++/40566 + * g++.dg/parse/cond5.C: New test. + 2009-07-10 Richard Guenther Backport from mainline diff --git a/gcc/testsuite/g++.dg/parse/cond5.C b/gcc/testsuite/g++.dg/parse/cond5.C new file mode 100644 index 000000000000..7ed9fbe892ec --- /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"; +} -- 2.47.2