re PR c++/81061 (ICE modifying read-only variable)
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 13 Dec 2017 20:29:11 +0000 (20:29 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 13 Dec 2017 20:29:11 +0000 (20:29 +0000)
/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.

From-SVN: r255613

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

index d298315e240155b20317a676b1e6e8b37550d0ea..d362c47f6dc87acf7ea69ce73df1ba4c583b653a 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2017-12-13  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/15272
index 7210f99fb083bdbbc1da97699293ad0825002fd2..8f3302f19334c5df2ff347be795b81aa004d2f22 100644 (file)
@@ -8037,8 +8037,7 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
     {
       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 43ef569fb1c12f270ed8acb8661b634f801099f3..5a3d8f2a3f001b70aa1a581e5d75117bfd5eba1f 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-13  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/81061
+       * g++.dg/other/const5.C: New.
+
 2017-12-13  Alexandre Oliva  <aoliva@redhat.com>
            Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/testsuite/g++.dg/other/const5.C b/gcc/testsuite/g++.dg/other/const5.C
new file mode 100644 (file)
index 0000000..fabe361
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/81061
+
+const int i = 0;
+
+void foo()
+{
+  (0, i) = 1;  // { dg-error "read-only" }
+}