OSDN Git Service

PR c++/30847
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Apr 2007 09:08:00 +0000 (09:08 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Apr 2007 09:08:00 +0000 (09:08 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123456 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/cond3.C [new file with mode: 0644]

index 755115e..192d7e8 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
 2007-03-30  Jason Merrill  <jason@redhat.com>
 
        PR c++/31187
index a5a3345..f3358c7 100644 (file)
@@ -5702,6 +5702,12 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
        tree cond;
        tree preeval = NULL_TREE;
 
        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
        rhs = stabilize_expr (rhs, &preeval);
 
        /* Check this here to avoid odd errors when trying to convert
index 5570d48..74691d2 100644 (file)
@@ -1,5 +1,8 @@
 2007-04-03  Jakub Jelinek  <jakub@redhat.com>
 
 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.
 
        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" }
+}