Hi,

in this error-recovery regression we ICE after a sensible diagnostic emitted by cp_build_unary_op, called by finish_unary_op_expr via build_x_unary_op. In principle we could dig deeper, but I don't think it makes sense for finish_unary_op_expr to go on having seen the error_mark_node returned by build_x_unary_op given that the purpose of its second half is only issuing warnings.

Tested x86_64-linux.

Thanks, Paolo.

//////////////////////


/cp
2018-09-25  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/84940
        * semantics.c (finish_unary_op_expr): Check return value of
        build_x_unary_op for error_mark_node.

/testsuite
2018-09-25  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/84940
        * g++.dg/expr/unary4.C: New.
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 264578)
+++ cp/semantics.c      (working copy)
@@ -2727,13 +2727,14 @@ finish_unary_op_expr (location_t op_loc, enum tree
   /* TODO: build_x_unary_op doesn't always honor the location.  */
   result.set_location (combined_loc);
 
-  tree result_ovl, expr_ovl;
+  if (result == error_mark_node)
+    return result;
 
   if (!(complain & tf_warning))
     return result;
 
-  result_ovl = result;
-  expr_ovl = expr;
+  tree result_ovl = result;
+  tree expr_ovl = expr;
 
   if (!processing_template_decl)
     expr_ovl = cp_fully_fold (expr_ovl);
Index: testsuite/g++.dg/expr/unary4.C
===================================================================
--- testsuite/g++.dg/expr/unary4.C      (nonexistent)
+++ testsuite/g++.dg/expr/unary4.C      (working copy)
@@ -0,0 +1,8 @@
+// PR c++/84940
+// { dg-additional-options -Wno-vla }
+
+void
+foo (int x)
+{
+  struct {} a[1][x](-a[0]); // { dg-error "wrong type argument to unary minus" 
}
+}

Reply via email to