re PR c++/30847 (ICE with invalid statement expression)
authorJakub Jelinek <jakub@redhat.com>
Tue, 3 Apr 2007 09:08:00 +0000 (11:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Apr 2007 09:08:00 +0000 (11:08 +0200)
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
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/cond3.C [new file with mode: 0644]

index 755115e4a935b4ee4a00bbecc4105c8839194613..192d7e8adfbb9b2f2405a8ab476b3eba4095619b 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-03  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <jason@redhat.com>
 
        PR c++/31187
index a5a33451cf98ecb3d1ef87beee80fa035a0efaa6..f3358c79c6c1d8302bf2ad05211f3438a9acdc9a 100644 (file)
@@ -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
index 5570d4806da905857539d9a8fa428b662c933868..74691d270a6608bab5786d003f5df200ef43dc24 100644 (file)
@@ -1,5 +1,8 @@
 2007-04-03  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..96d9c1e
--- /dev/null
@@ -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" }
+}