]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/40566 (rejects promoted throw)
authorRichard Guenther <rguenther@suse.de>
Fri, 10 Jul 2009 16:02:59 +0000 (16:02 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 10 Jul 2009 16:02:59 +0000 (16:02 +0000)
2009-07-10  Richard Guenther  <rguenther@suse.de>

Backport from mainline
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.

* g++.dg/parse/cond5.C: New test.

From-SVN: r149488

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/cond5.C [new file with mode: 0644]

index 282148ea546fb7899d018f7fe02cd607f322945c..18de990737bb7dcf6575bbb8c3efb1020d576fe3 100644 (file)
@@ -1,3 +1,12 @@
+2009-07-10  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       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.
+
 2009-07-10  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
index d5de95c1b46c7dfeb5f68539b379b12524622115..84d4ec7653ea9a85dba5fe3a3a27a310f76d4dd8 100644 (file)
@@ -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;
index b3cc101ee35b91b24aa3725285b47151a5c485dd..125bb87ac1ded5b783548bc7dd2e5e5884bc6225 100644 (file)
@@ -1,3 +1,11 @@
+2009-07-10  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2009-06-30  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/40566
+       * g++.dg/parse/cond5.C: New test.
+
 2009-07-10  Richard Guenther  <rguenther@suse.de>
 
        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 (file)
index 0000000..7ed9fbe
--- /dev/null
@@ -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";
+}