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]

fix 14804


The problem here is that we (on purpose) removed everything that would
have told varasm.c that the const object needs to live in writable memory.
The solution is to temporarily un-mark the object from being const; this
is the same as what we do for objects with constructors, so this seems
safe.

Ok?


r~


	* decl.c (cp_finish_decl): Preserve TREE_READONLY more often.
	* typeck2.c (split_nonconstant_init): Clear TREE_READONLY.

Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1199
diff -c -p -d -r1.1199 decl.c
*** decl.c	30 Mar 2004 23:44:58 -0000	1.1199
--- decl.c	1 Apr 2004 17:55:56 -0000
*************** cp_finish_decl (tree decl, tree init, tr
*** 4753,4768 ****
    if (TREE_CODE (decl) != FUNCTION_DECL)
      ttype = target_type (type);
  
!   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
!       && (TYPE_NEEDS_CONSTRUCTING (type) 
! 	  || TREE_CODE (type) == REFERENCE_TYPE))
      {
-       /* Currently, GNU C++ puts constants in text space, making them
- 	 impossible to initialize.  In the future, one would hope for
- 	 an operating system which understood the difference between
- 	 initialization and the running of a program.  */
        was_readonly = 1;
!       TREE_READONLY (decl) = 0;
      }
  
    if (TREE_CODE (decl) == VAR_DECL)
--- 4753,4769 ----
    if (TREE_CODE (decl) != FUNCTION_DECL)
      ttype = target_type (type);
  
!   
!   /* Currently, GNU C++ puts constants in text space, making them
!      impossible to initialize.  In the future, one would hope for
!      an operating system which understood the difference between
!      initialization and the running of a program.  */
!   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl))
      {
        was_readonly = 1;
!       if (TYPE_NEEDS_CONSTRUCTING (type) 
! 	  || TREE_CODE (type) == REFERENCE_TYPE)
! 	TREE_READONLY (decl) = 0;
      }
  
    if (TREE_CODE (decl) == VAR_DECL)
Index: typeck2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck2.c,v
retrieving revision 1.155
diff -c -p -d -r1.155 typeck2.c
*** typeck2.c	16 Mar 2004 22:18:07 -0000	1.155
--- typeck2.c	1 Apr 2004 17:55:56 -0000
*************** split_nonconstant_init (tree dest, tree 
*** 380,385 ****
--- 380,386 ----
        code = build1 (STMT_EXPR, void_type_node, code);
        TREE_SIDE_EFFECTS (code) = 1;
        DECL_INITIAL (dest) = init;
+       TREE_READONLY (dest) = 0;
      }
    else
      code = build (INIT_EXPR, TREE_TYPE (dest), dest, init);
Index: testsuite/g++.dg/init/static2.C
===================================================================
RCS file: testsuite/g++.dg/init/static2.C
diff -N testsuite/g++.dg/init/static2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/static2.C	1 Apr 2004 20:15:49 -0000
***************
*** 0 ****
--- 1,25 ----
+ // PR 14804
+ // { dg-do run }
+ 
+ struct A {
+   virtual void foo() = 0;
+ };
+ 
+ struct B : public A {
+   virtual void bar() = 0;
+ };
+ 
+ typedef void (A::*mfptr)();
+ 
+ struct D {
+   mfptr p;
+ };
+ 
+ static const D ds[] = {
+   { reinterpret_cast<mfptr>(&B::bar) },
+ };
+ 
+ int main()
+ {
+   return 0;
+ }


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