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.
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);