Commit a09c81b4 by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/71528 (multiple extern reference declarations produce uninitialized access)

	PR c++/71528
	* decl.c (duplicate_decls): For DECL_INITIALIZED_P non-external
	olddecl vars, preserve their TREE_READONLY bit.

	* g++.dg/opt/pr71528.C: New test.

From-SVN: r237458
parent 5618c53f
2016-06-14 Jakub Jelinek <jakub@redhat.com>
PR c++/71528
* decl.c (duplicate_decls): For DECL_INITIALIZED_P non-external
olddecl vars, preserve their TREE_READONLY bit.
PR c++/71516
* decl.c (complete_vars): Handle gracefully type == error_mark_node.
......
......@@ -2066,6 +2066,14 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
if (VAR_P (newdecl))
{
DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
/* For already initialized vars, TREE_READONLY could have been
cleared in cp_finish_decl, because the var needs runtime
initialization or destruction. Make sure not to set
TREE_READONLY on it again. */
if (DECL_INITIALIZED_P (olddecl)
&& !DECL_EXTERNAL (olddecl)
&& !TREE_READONLY (olddecl))
TREE_READONLY (newdecl) = 0;
DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
|= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
......
2016-06-14 Jakub Jelinek <jakub@redhat.com>
PR c++/71528
* g++.dg/opt/pr71528.C: New test.
PR c++/71516
* g++.dg/init/pr71516.C: New test.
......
// PR c++/71528
// { dg-do run }
// { dg-options "-O2" }
extern int &x;
int y;
int &
foo ()
{
return y;
}
int &x = foo ();
int
main ()
{
if (&x != &y)
__builtin_abort ();
}
extern int &x;
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