From: Jason Merrill Date: Wed, 9 Jan 2013 18:55:12 +0000 (-0500) Subject: re PR c++/55893 ([C++11] runtime segfault with static const object with virtual destr... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=96924e7e64db44da01b320f6cbe6cbb8676ee1ef;p=gcc.git re PR c++/55893 ([C++11] runtime segfault with static const object with virtual destructor) PR c++/55893 * decl.c (cp_finish_decl): Clear TREE_READONLY if the variable needs destruction. From-SVN: r195062 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d67a3c40f35..fe64da57d5b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-01-09 Jason Merrill + + PR c++/55893 + * decl.c (cp_finish_decl): Clear TREE_READONLY if the variable + needs destruction. + 2013-01-09 Jakub Jelinek PR c/48418 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9640824f726..c3622ecf488 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6417,6 +6417,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, } else if (was_readonly) TREE_READONLY (decl) = 1; + + /* Likewise if it needs destruction. */ + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) + TREE_READONLY (decl) = 0; } make_rtl_for_nonlocal_decl (decl, init, asmspec); diff --git a/gcc/testsuite/g++.dg/init/const9.C b/gcc/testsuite/g++.dg/init/const9.C new file mode 100644 index 00000000000..ba1dfd4bc46 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/const9.C @@ -0,0 +1,12 @@ +// PR c++/55893 +// { dg-final { scan-assembler-not "rodata" } } + +struct foo +{ + virtual ~foo (); +}; + +int main () +{ + static const foo tmp; +}