My fix for PR 49673 made it so that objects with constant initialization
semantics through constexpr can go into rodata now. But objects with
non-trivial destruction semantics still need to go into writable data so
that the destructor can modify the object.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
commit f7142c9ff05259adbda2cb5797088b6a2c281ad9
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Jan 9 11:44:13 2013 -0500
PR c++/55893
* decl.c (cp_finish_decl): Clear TREE_READONLY if the variable
needs destruction.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 9640824..c3622ec 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 0000000..ba1dfd4
--- /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;
+}