This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Propagate CLASSTYPE_HAS_MUTABLE from bases to derived classes (PR c++/77375)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 29 Aug 2016 21:37:34 +0200
- Subject: [C++ PATCH] Propagate CLASSTYPE_HAS_MUTABLE from bases to derived classes (PR c++/77375)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The following testcase fails (foo is allocated in .rodata and modified)
because while we clear TREE_READONLY for classes with mutable members, we
don't do that if they only have bases with mutable members.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for
trunk? What about release branches?
2016-08-29 Jakub Jelinek <jakub@redhat.com>
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.
--- gcc/cp/class.c.jj 2016-08-12 17:33:42.000000000 +0200
+++ gcc/cp/class.c 2016-08-29 11:54:10.387061502 +0200
@@ -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:
...
--- gcc/testsuite/g++.dg/cpp0x/mutable1.C.jj 2016-08-29 12:05:13.700212552 +0200
+++ gcc/testsuite/g++.dg/cpp0x/mutable1.C 2016-08-29 12:03:51.000000000 +0200
@@ -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;
+}
Jakub