From: Jakub Jelinek Date: Fri, 16 Sep 2016 20:21:29 +0000 (+0200) Subject: re PR c++/77375 (constant object with mutable subobject allocated in read-only memory) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e7d61178099e49835d84fba9c5bffbace0f26099;p=gcc.git re PR c++/77375 (constant object with mutable subobject allocated in read-only memory) PR c++/77375 * class.c (check_bases): Set CLASSTYPE_HAS_MUTABLE if any TYPE_HAS_MUTABLE_P for any bases. * g++.dg/cpp0x/mutable1.C: New test. From-SVN: r240195 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b5140fe3d0..ee0818e2edf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-09-16 Jakub Jelinek + + PR c++/77375 + * class.c (check_bases): Set CLASSTYPE_HAS_MUTABLE if any + TYPE_HAS_MUTABLE_P for any bases. + 2016-09-16 Jason Merrill * class.c (check_bases, set_one_vmethod_tm_attributes): Use diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 150f46f6e19..7362c732646 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1796,6 +1796,8 @@ check_bases (tree t, SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t) | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype)); + if (TYPE_HAS_MUTABLE_P (basetype)) + CLASSTYPE_HAS_MUTABLE (t) = 1; /* A standard-layout class is a class that: ... diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3c992548d11..bd3f70f0d5f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-16 Jakub Jelinek + + PR c++/77375 + * g++.dg/cpp0x/mutable1.C: New test. + 2016-09-16 Steven G. Kargl PR fortran/77612 diff --git a/gcc/testsuite/g++.dg/cpp0x/mutable1.C b/gcc/testsuite/g++.dg/cpp0x/mutable1.C new file mode 100644 index 00000000000..4dd37185d72 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/mutable1.C @@ -0,0 +1,12 @@ +// PR c++/77375 +// { dg-do run { target c++11 } } + +struct Base { mutable int i; }; +struct Derived : Base {}; +const Derived foo{}; + +int +main () +{ + foo.i = 42; +}