This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Clear TREE_READONLY if TYPE_NEEDS_CONSTRUCTING somewhat later (fix PR c++/20073)


Hi!

As shown by the testcase below, clearing TREE_READONLY for decls
that needs constructing is too early.  Even close to the end of
cp_finish_decl a type that has been before not TYPE_NEEDS_CONSTRUCTING
might become one.
cp_finish_decl is run after the start_decl_1, so covers the initial
testcase (btw, shouldn't we have add scanrtl.exp (modified scantre.exp)?
Otherwise I don't know how to reliably test for the original c++/19813
bug).

I've bootstrapped/regtested this on i386-redhat-linux, ok to commit?

2005-02-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/20073
	* decl.c (start_decl_1): Revert 2005-02-1{8,9} changes.
	(cp_finish_decl): Clear TREE_READONLY flag if
	its type has TYPE_NEEDS_CONSTRUCTING.

	* g++.dg/other/const3.C: New test.

--- gcc/cp/decl.c.jj	2005-02-19 00:16:01.000000000 +0100
+++ gcc/cp/decl.c	2005-02-19 21:10:49.818177253 +0100
@@ -3823,14 +3823,6 @@ start_decl_1 (tree decl)
      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
      will be set correctly.  */
   maybe_push_cleanup_level (type);
-
-  /* An object declared 'const' is only readonly after it is
-     initialized.  We don't have any way of expressing this currently,
-     so we need to be conservative and unset TREE_READONLY for types
-     with constructors.  Otherwise aliasing code will ignore stores in
-     an inline constructor.  */
-   if (type != error_mark_node && TYPE_NEEDS_CONSTRUCTING (type))
-     TREE_READONLY (decl) = 0;
 }
 
 /* Handle initialization of references.  DECL, TYPE, and INIT have the
@@ -4952,7 +4943,14 @@ cp_finish_decl (tree decl, tree init, tr
 
  finish_end:
 
-  if (was_readonly)
+  /* An object declared 'const' is only readonly after it is
+     initialized.  We don't have any way of expressing this currently,
+     so we need to be conservative and unset TREE_READONLY for types
+     with constructors.  Otherwise aliasing code will ignore stores in
+     an inline constructor.  */
+  if (type != error_mark_node && TYPE_NEEDS_CONSTRUCTING (type))
+    TREE_READONLY (decl) = 0;
+  else if (was_readonly)
     TREE_READONLY (decl) = 1;
 
   /* If this was marked 'used', be sure it will be output.  */
--- gcc/testsuite/g++.dg/other/const3.C.jj	2005-02-19 17:34:23.000000000 +0100
+++ gcc/testsuite/g++.dg/other/const3.C	2005-02-19 17:33:44.000000000 +0100
@@ -0,0 +1,4 @@
+// PR c++/20073
+// { dg-do compile }
+template<int> struct A { A (); };
+const A<0> x[] = { A<0> () };


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]