diff mbox series

[C++] PR 81061 ("[7/8 Regression] ICE modifying read-only variable")

Message ID 978b70fd-2c32-33c0-2697-92bdead883a0@oracle.com
State New
Headers show
Series [C++] PR 81061 ("[7/8 Regression] ICE modifying read-only variable") | expand

Commit Message

Paolo Carlini Dec. 13, 2017, 10:32 a.m. UTC
Hi,

in this simple error recovery regression we ICE during gimplification 
after sensible diagnostic about assigning to a read-only location. The 
problem can be avoided by simply returning immediately error_mark_node 
upon cxx_readonly_error - the rest of the function does the same, ie, 
doesn't try to proceed when complain & tf_error. I also noticed that 
clang appears to behave in the same way for this error. Tested x86_64-linux.

Thanks, Paolo

////////////////////////
/cp
2017-12-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81061
	* typeck.c (cp_build_modify_expr): Upon cxx_readonly_error
	immediately return error_mark_node.

/testsuite
2017-12-13  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81061
	* g++.dg/other/const5.C: New.

Comments

Jason Merrill Dec. 13, 2017, 5:41 p.m. UTC | #1
OK.

On Wed, Dec 13, 2017 at 5:32 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
> in this simple error recovery regression we ICE during gimplification after
> sensible diagnostic about assigning to a read-only location. The problem can
> be avoided by simply returning immediately error_mark_node upon
> cxx_readonly_error - the rest of the function does the same, ie, doesn't try
> to proceed when complain & tf_error. I also noticed that clang appears to
> behave in the same way for this error. Tested x86_64-linux.
>
> Thanks, Paolo
>
> ////////////////////////
>
diff mbox series

Patch

Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 255602)
+++ cp/typeck.c	(working copy)
@@ -8037,8 +8037,7 @@  cp_build_modify_expr (location_t loc, tree lhs, en
     {
       if (complain & tf_error)
 	cxx_readonly_error (lhs, lv_assign);
-      else
-	return error_mark_node;
+      return error_mark_node;
     }
 
   /* If storing into a structure or union member, it may have been given a
Index: testsuite/g++.dg/other/const5.C
===================================================================
--- testsuite/g++.dg/other/const5.C	(nonexistent)
+++ testsuite/g++.dg/other/const5.C	(working copy)
@@ -0,0 +1,8 @@ 
+// PR c++/81061
+
+const int i = 0;
+
+void foo()
+{
+  (0, i) = 1;  // { dg-error "read-only" }
+}