Commit 01ff88c5 by Jason Merrill

c++: -fmerge-all-constants vs. destructors [PR91529]

cp_finish_decl avoids setting TREE_READONLY on TREE_STATIC variables that
have non-constant construction or destruction, but -fmerge-all-constants was
converting an automatic variable to static while leaving TREE_READONLY set.

Fixed by clearing the flag in cp_finish_decl in the presence of
-fmerge-all-constants.

gcc/cp/ChangeLog
2020-05-01  Jason Merrill  <jason@redhat.com>

	PR c++/91529
	* decl.c (cp_finish_decl): Also clear TREE_READONLY if
	-fmerge-all-constants.
parent 4cee8136
2020-05-25 Jason Merrill <jason@redhat.com>
PR c++/91529
* decl.c (cp_finish_decl): Also clear TREE_READONLY if
-fmerge-all-constants.
2020-05-25 Jason Merrill <jason@redhat.com>
PR c++/93822
* pt.c (tsubst_decl): Make sure DECL_VALUE_EXPR continues to have
the same type as the variable.
......
......@@ -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
......
// 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 };
}
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