@@ -7833,7 +7833,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
maybe_commonize_var (decl);
}
- if (var_definition_p && TREE_STATIC (decl))
+ if (var_definition_p
+ /* With -fmerge-all-constants, gimplify_init_constructor
+ might add TREE_STATIC to the variable. */
+ && (TREE_STATIC (decl) || flag_merge_constants >= 2))
{
/* If a TREE_READONLY variable needs initialization
at runtime, it is no longer readonly and we need to
new file mode 100644
@@ -0,0 +1,14 @@
+// PR c++/91529
+// { dg-do run }
+// { dg-additional-options -fmerge-all-constants }
+
+struct A
+{
+ int i[2];
+ ~A() { i[0] = 0; }
+};
+
+int main()
+{
+ const A a = { 1,2 };
+}