re PR c++/55893 ([C++11] runtime segfault with static const object with virtual destr...
authorJason Merrill <jason@redhat.com>
Wed, 9 Jan 2013 18:55:12 +0000 (13:55 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 9 Jan 2013 18:55:12 +0000 (13:55 -0500)
PR c++/55893
* decl.c (cp_finish_decl): Clear TREE_READONLY if the variable
needs destruction.

From-SVN: r195062

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/init/const9.C [new file with mode: 0644]

index d67a3c40f35536edb0e9971e98da0233057eaddc..fe64da57d5b32790c778a892188d683d21878a98 100644 (file)
@@ -1,3 +1,9 @@
+2013-01-09  Jason Merrill  <jason@redhat.com>
+
+       PR c++/55893
+       * decl.c (cp_finish_decl): Clear TREE_READONLY if the variable
+       needs destruction.
+
 2013-01-09  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/48418
index 9640824f7265c25760139f7089a40d7642681dcd..c3622ecf48891d3c2cdb1679c75a3b9a2f4a3471 100644 (file)
@@ -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 (file)
index 0000000..ba1dfd4
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/55893
+// { dg-final { scan-assembler-not "rodata" } }
+
+struct foo
+{
+  virtual ~foo ();
+};
+
+int main ()
+{
+  static const foo tmp;
+}