Commit 6407bc67 by Richard Henderson Committed by Richard Henderson

re PR c++/14804 ([unit-at-a-time] initializing const data with…

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: r80318
parent 54fdc910
2004-04-01 Richard Henderson <rth@redhat.com>
PR c++/14804
* decl.c (cp_finish_decl): Preserve TREE_READONLY more often.
* typeck2.c (split_nonconstant_init): Clear TREE_READONLY.
2004-04-01 Mark Mitchell <mark@codesourcery.com> 2004-04-01 Mark Mitchell <mark@codesourcery.com>
PR c++/14810 PR c++/14810
......
...@@ -4753,15 +4753,16 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags) ...@@ -4753,15 +4753,16 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
if (TREE_CODE (decl) != FUNCTION_DECL) if (TREE_CODE (decl) != FUNCTION_DECL)
ttype = target_type (type); 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 /* Currently, GNU C++ puts constants in text space, making them
impossible to initialize. In the future, one would hope for impossible to initialize. In the future, one would hope for
an operating system which understood the difference between an operating system which understood the difference between
initialization and the running of a program. */ initialization and the running of a program. */
if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl))
{
was_readonly = 1; was_readonly = 1;
if (TYPE_NEEDS_CONSTRUCTING (type)
|| TREE_CODE (type) == REFERENCE_TYPE)
TREE_READONLY (decl) = 0; TREE_READONLY (decl) = 0;
} }
......
...@@ -380,6 +380,7 @@ split_nonconstant_init (tree dest, tree init) ...@@ -380,6 +380,7 @@ split_nonconstant_init (tree dest, tree init)
code = build1 (STMT_EXPR, void_type_node, code); code = build1 (STMT_EXPR, void_type_node, code);
TREE_SIDE_EFFECTS (code) = 1; TREE_SIDE_EFFECTS (code) = 1;
DECL_INITIAL (dest) = init; DECL_INITIAL (dest) = init;
TREE_READONLY (dest) = 0;
} }
else else
code = build (INIT_EXPR, TREE_TYPE (dest), dest, init); code = build (INIT_EXPR, TREE_TYPE (dest), dest, init);
......
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment