From 66e22c4876d032f07b752ff4d330f69a34d6602e Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 1 Apr 2004 13:48:06 -0800 Subject: [PATCH] re PR c++/14804 ([unit-at-a-time] initializing const data with reinterpret_cast-ed pointer-to-member function crashes) PR c++/14804 * decl.c (cp_finish_decl): Preserve TREE_READONLY more often. * typeck2.c (split_nonconstant_init): Clear TREE_READONLY. From-SVN: r80325 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 19 ++++++++++--------- gcc/cp/typeck2.c | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b3398a064604..02082405ab29 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-04-01 Richard Henderson + + PR c++/14804 + * decl.c (cp_finish_decl): Preserve TREE_READONLY more often. + * typeck2.c (split_nonconstant_init): Clear TREE_READONLY. + 2003-03-17 Matt Austern Backport: diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 902416d24df0..91ef96afb9ee 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8887,16 +8887,17 @@ cp_finish_decl (decl, init, asmspec_tree, flags) 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. */ + + /* 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; - TREE_READONLY (decl) = 0; + if (TYPE_NEEDS_CONSTRUCTING (type) + || TREE_CODE (type) == REFERENCE_TYPE) + TREE_READONLY (decl) = 0; } if (TREE_CODE (decl) == FIELD_DECL && asmspec) diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index d80463213a0f..e4929275b918 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -391,6 +391,7 @@ split_nonconstant_init (tree dest, tree init) 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); -- 2.47.2