From df3473facbac90274ca6e5d6e6ce3db2152dce35 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 3 Apr 2007 11:08:00 +0200 Subject: [PATCH] re PR c++/30847 (ICE with invalid statement expression) PR c++/30847 * typeck.c (build_modify_expr): For COND_EXPR on LHS, if RHS has void type issue error and return early. * g++.dg/parse/cond3.C: New test. From-SVN: r123456 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 6 ++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/parse/cond3.C | 15 +++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/cond3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 755115e4a935..192d7e8adfbb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-04-03 Jakub Jelinek + + PR c++/30847 + * typeck.c (build_modify_expr): For COND_EXPR on LHS, if RHS has void + type issue error and return early. + 2007-03-30 Jason Merrill PR c++/31187 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index a5a33451cf98..f3358c79c6c1 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5702,6 +5702,12 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs) tree cond; tree preeval = NULL_TREE; + if (VOID_TYPE_P (TREE_TYPE (rhs))) + { + error ("void value not ignored as it ought to be"); + return error_mark_node; + } + rhs = stabilize_expr (rhs, &preeval); /* Check this here to avoid odd errors when trying to convert diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5570d4806da9..74691d270a66 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2007-04-03 Jakub Jelinek + PR c++/30847 + * g++.dg/parse/cond3.C: New test. + PR middle-end/30704 * gcc.c-torture/execute/ieee/pr30704.c: New test. diff --git a/gcc/testsuite/g++.dg/parse/cond3.C b/gcc/testsuite/g++.dg/parse/cond3.C new file mode 100644 index 000000000000..96d9c1e3b5f6 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/cond3.C @@ -0,0 +1,15 @@ +// PR c++/30847 +// { dg-do compile } +// { dg-options "" } + +int j, k, l; +extern void baz (); + +void +foo (int i) +{ + (i ? j : k) = ({ l++; (void) l; }); // { dg-error "void value not ignored" } + (i ? j : k) += ({ l++; (void) l; }); // { dg-error "void value not ignored" } + (i ? j : k) = baz (); // { dg-error "void value not ignored" } + (i ? j : k) *= baz (); // { dg-error "void value not ignored" } +}