From 33a49c17e8437b2405616dbd4294a59cd339b880 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 30 Oct 2007 23:40:13 +0100 Subject: [PATCH] re PR c++/33709 (Type verification failure with new expression) PR c++/33709 * fold-const.c (fold_binary): If one argument is COMPOUND_EXPR, convert second operand of COMPOUND_EXPR to the original type of that argument. * g++.dg/opt/compound1.C: New test. From-SVN: r129785 --- gcc/ChangeLog | 7 +++++++ gcc/fold-const.c | 9 ++++++--- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/opt/compound1.C | 11 +++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/opt/compound1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 14c0428daf2..1f0196dcbbb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2007-10-30 Jakub Jelinek + + PR c++/33709 + * fold-const.c (fold_binary): If one argument is COMPOUND_EXPR, + convert second operand of COMPOUND_EXPR to the original type of + that argument. + 2007-10-30 Richard Guenther * tree-ssa-operands.c (add_vars_for_offset): Fix exit test diff --git a/gcc/fold-const.c b/gcc/fold-const.c index fd5a7085e91..2598ec1e18f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9504,12 +9504,15 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) if (TREE_CODE (arg0) == COMPOUND_EXPR) return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), fold_build2 (code, type, - TREE_OPERAND (arg0, 1), op1)); + fold_convert (TREE_TYPE (op0), + TREE_OPERAND (arg0, 1)), + op1)); if (TREE_CODE (arg1) == COMPOUND_EXPR && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0), - fold_build2 (code, type, - op0, TREE_OPERAND (arg1, 1))); + fold_build2 (code, type, op0, + fold_convert (TREE_TYPE (op1), + TREE_OPERAND (arg1, 1)))); if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4fcafd01bbd..82dbb7a6715 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2007-10-30 Jakub Jelinek + PR c++/33709 + * g++.dg/opt/compound1.C: New test. + PR c++/33616 * g++.dg/template/ptrmem18.C: New test. diff --git a/gcc/testsuite/g++.dg/opt/compound1.C b/gcc/testsuite/g++.dg/opt/compound1.C new file mode 100644 index 00000000000..cf81e698089 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/compound1.C @@ -0,0 +1,11 @@ +// PR c++/33709 +// { dg-do compile } +// { dg-options "-O2" } + +class S { + virtual void foo (); +}; +struct T { + S *s; + void bar (unsigned x) { s = (new S[1]) - x; } +}; -- 2.30.2