Hi,

an ICE on invalid, regression in 4.7 and 4.8. In 4.7 (vs 4.6) we started using stabilize_expr in one more place in cp_build_modify_expr without also adding a preliminary check that the expr isn't of void type, thus we can easily end up calling build_type_target_expr_with_type on it and crash.

The fix I tested could be even simpler but I guess we want to also emit the error line " in evaluation of...", like in 4.6. If you can't imagine how we could regress with this sort of fix (I can't ;) probably the issue should be also addressed in 4.7, this kind of invalid code must be quite common.

Thanks,
Paolo.

/////////////////////////
/cp
2012-05-26  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/53491
        * typeck.c (cp_build_modify_expr): Fo binary ops, check that the
        right-hand side isn't of void type.

/testsuite
2012-05-26  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/53491
        * g++.dg/parse/crash60.C: New.

Index: testsuite/g++.dg/parse/crash60.C
===================================================================
--- testsuite/g++.dg/parse/crash60.C    (revision 0)
+++ testsuite/g++.dg/parse/crash60.C    (revision 0)
@@ -0,0 +1,14 @@
+// PR c++/53491
+
+struct M
+{
+  void pop();
+};
+
+void foo()
+{
+  int result = 0;
+  M m;
+
+  result += m.pop();  // { dg-error "not ignored|in evaluation" }
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 187901)
+++ cp/typeck.c (working copy)
@@ -6949,10 +6949,20 @@ cp_build_modify_expr (tree lhs, enum tree_code mod
          lhs = stabilize_reference (lhs);
          if (TREE_SIDE_EFFECTS (rhs))
            rhs = mark_rvalue_use (rhs);
-         rhs = stabilize_expr (rhs, &init);
-         newrhs = cp_build_binary_op (input_location,
-                                      modifycode, lhs, rhs,
-                                      complain);
+
+         if (VOID_TYPE_P (TREE_TYPE (rhs)))
+           {
+             if (complain & tf_error)
+               error ("void value not ignored as it ought to be");
+             newrhs = error_mark_node;
+           }
+         else
+           {
+             rhs = stabilize_expr (rhs, &init);
+             newrhs = cp_build_binary_op (input_location,
+                                          modifycode, lhs, rhs,
+                                          complain);
+           }
          if (newrhs == error_mark_node)
            {
              if (complain & tf_error)

Reply via email to