extern tree create_temporary_var (tree);
extern void initialize_vtbl_ptrs (tree);
extern tree scalar_constant_value (tree);
-extern tree decl_really_constant_value (tree);
+extern tree decl_constant_value (tree, bool);
+extern tree decl_really_constant_value (tree, bool = true);
extern int diagnose_uninitialized_cst_or_ref_member (tree, bool, bool);
extern tree build_vtbl_address (tree);
extern bool maybe_reject_flexarray_init (tree, tree);
recursively); otherwise, return DECL. If STRICT_P, the
initializer is only returned if DECL is a
constant-expression. If RETURN_AGGREGATE_CST_OK_P, it is ok to
- return an aggregate constant. */
+ return an aggregate constant. If UNSHARE_P, return an unshared
+ copy of the initializer. */
static tree
-constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
+constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p,
+ bool unshare_p)
{
while (TREE_CODE (decl) == CONST_DECL
|| decl_constant_var_p (decl)
&& !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
&& DECL_NONTRIVIALLY_INITIALIZED_P (decl))
break;
- decl = unshare_expr (init);
+ decl = init;
}
- return decl;
+ return unshare_p ? unshare_expr (decl) : decl;
}
/* If DECL is a CONST_DECL, or a constant VAR_DECL initialized by constant
scalar_constant_value (tree decl)
{
return constant_value_1 (decl, /*strict_p=*/true,
- /*return_aggregate_cst_ok_p=*/false);
+ /*return_aggregate_cst_ok_p=*/false,
+ /*unshare_p=*/true);
}
-/* Like scalar_constant_value, but can also return aggregate initializers. */
+/* Like scalar_constant_value, but can also return aggregate initializers.
+ If UNSHARE_P, return an unshared copy of the initializer. */
tree
-decl_really_constant_value (tree decl)
+decl_really_constant_value (tree decl, bool unshare_p /*= true*/)
{
return constant_value_1 (decl, /*strict_p=*/true,
- /*return_aggregate_cst_ok_p=*/true);
+ /*return_aggregate_cst_ok_p=*/true,
+ /*unshare_p=*/unshare_p);
}
-/* A more relaxed version of scalar_constant_value, used by the
+/* A more relaxed version of decl_really_constant_value, used by the
common C/C++ code. */
tree
-decl_constant_value (tree decl)
+decl_constant_value (tree decl, bool unshare_p)
{
return constant_value_1 (decl, /*strict_p=*/processing_template_decl,
- /*return_aggregate_cst_ok_p=*/true);
+ /*return_aggregate_cst_ok_p=*/true,
+ /*unshare_p=*/unshare_p);
+}
+
+tree
+decl_constant_value (tree decl)
+{
+ return decl_constant_value (decl, /*unshare_p=*/true);
}
\f
/* Common subroutines of build_new and build_vec_delete. */