From ae51fb47811a9d5a3cfbb67677dae0eababc263d Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 13 Dec 2017 20:29:11 +0000 Subject: [PATCH] re PR c++/81061 (ICE modifying read-only variable) /cp 2017-12-13 Paolo Carlini PR c++/81061 * typeck.c (cp_build_modify_expr): Upon cxx_readonly_error immediately return error_mark_node. /testsuite 2017-12-13 Paolo Carlini PR c++/81061 * g++.dg/other/const5.C: New. From-SVN: r255613 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 3 +-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/other/const5.C | 8 ++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/const5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d298315e240..d362c47f6dc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-12-13 Paolo Carlini + + PR c++/81061 + * typeck.c (cp_build_modify_expr): Upon cxx_readonly_error + immediately return error_mark_node. + 2017-12-13 Nathan Sidwell PR c++/15272 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7210f99fb08..8f3302f1933 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 43ef569fb1c..5a3d8f2a3f0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-13 Paolo Carlini + + PR c++/81061 + * g++.dg/other/const5.C: New. + 2017-12-13 Alexandre Oliva Jakub Jelinek diff --git a/gcc/testsuite/g++.dg/other/const5.C b/gcc/testsuite/g++.dg/other/const5.C new file mode 100644 index 00000000000..fabe361d206 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/const5.C @@ -0,0 +1,8 @@ +// PR c++/81061 + +const int i = 0; + +void foo() +{ + (0, i) = 1; // { dg-error "read-only" } +} -- 2.30.2