re PR c++/77375 (constant object with mutable subobject allocated in read-only memory)
authorJakub Jelinek <jakub@redhat.com>
Fri, 16 Sep 2016 20:21:29 +0000 (22:21 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 16 Sep 2016 20:21:29 +0000 (22:21 +0200)
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

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/mutable1.C [new file with mode: 0644]

index 1b5140fe3d0f6398ab6aca3c9a133b3875faddee..ee0818e2edfedac4ad33d389ba1f9ef5d1dbc553 100644 (file)
@@ -1,3 +1,9 @@
+2016-09-16  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.
+
 2016-09-16  Jason Merrill  <jason@redhat.com>
 
        * class.c (check_bases, set_one_vmethod_tm_attributes): Use
index 150f46f6e19dffb1c58d358105f3f8819f8b5ae1..7362c732646bf6af5f16fcad13d8fcb185de673e 100644 (file)
@@ -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:
          ...
index 3c992548d111a139a761b2097d647161aacd704b..bd3f70f0d5f80894ca837e6ee89a8c2cd4bef4a0 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/77375
+       * g++.dg/cpp0x/mutable1.C: New test.
+
 2016-09-16  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        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 (file)
index 0000000..4dd3718
--- /dev/null
@@ -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;
+}