public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Propagate CLASSTYPE_HAS_MUTABLE from bases to derived classes (PR c++/77375)
@ 2016-08-29 19:37 Jakub Jelinek
  2016-09-16 19:47 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-08-29 19:37 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Propagate CLASSTYPE_HAS_MUTABLE from bases to derived classes (PR c++/77375)
  2016-08-29 19:37 [C++ PATCH] Propagate CLASSTYPE_HAS_MUTABLE from bases to derived classes (PR c++/77375) Jakub Jelinek
@ 2016-09-16 19:47 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-09-16 19:47 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

OK.

On Mon, Aug 29, 2016 at 3:37 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-16 19:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-29 19:37 [C++ PATCH] Propagate CLASSTYPE_HAS_MUTABLE from bases to derived classes (PR c++/77375) Jakub Jelinek
2016-09-16 19:47 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).