+2011-10-09 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/38980
+ * init.c (constant_value_1): Add bool parameter.
+ (decl_constant_value_safe): Add.
+ (integral_constant_value): Adjust.
+ (decl_constant_value): Adjust.
+ * cp-tree.h (decl_constant_value_safe): Declare.
+ * typeck.c (decay_conversion): Use decl_constant_value_safe.
+ * call.c (convert_like_real): Likewise.
+
2011-10-09 Jakub Jelinek <jakub@redhat.com>
Diego Novillo <dnovillo@google.com>
constant initializer, return the initializer (or, its initializers,
recursively); otherwise, return DECL. If INTEGRAL_P, the
initializer is only returned if DECL is an integral
- constant-expression. */
+ constant-expression. If RETURN_AGGREGATE_CST_OK_P, it is ok to
+ return an aggregate constant. */
static tree
-constant_value_1 (tree decl, bool integral_p)
+constant_value_1 (tree decl, bool integral_p, bool return_aggregate_cst_ok_p)
{
while (TREE_CODE (decl) == CONST_DECL
|| (integral_p
if (!init
|| !TREE_TYPE (init)
|| !TREE_CONSTANT (init)
- || (!integral_p
- /* Do not return an aggregate constant (of which
- string literals are a special case), as we do not
- want to make inadvertent copies of such entities,
- and we must be sure that their addresses are the
- same everywhere. */
+ || (!integral_p && !return_aggregate_cst_ok_p
+ /* Unless RETURN_AGGREGATE_CST_OK_P is true, do not
+ return an aggregate constant (of which string
+ literals are a special case), as we do not want
+ to make inadvertent copies of such entities, and
+ we must be sure that their addresses are the
+ same everywhere. */
&& (TREE_CODE (init) == CONSTRUCTOR
|| TREE_CODE (init) == STRING_CST)))
break;
tree
integral_constant_value (tree decl)
{
- return constant_value_1 (decl, /*integral_p=*/true);
+ return constant_value_1 (decl, /*integral_p=*/true,
+ /*return_aggregate_cst_ok_p=*/false);
}
/* A more relaxed version of integral_constant_value, used by the
- common C/C++ code and by the C++ front end for optimization
- purposes. */
+ common C/C++ code. */
tree
decl_constant_value (tree decl)
{
- return constant_value_1 (decl,
- /*integral_p=*/processing_template_decl);
+ return constant_value_1 (decl, /*integral_p=*/processing_template_decl,
+ /*return_aggregate_cst_ok_p=*/true);
+}
+
+/* A version of integral_constant_value used by the C++ front end for
+ optimization purposes. */
+
+tree
+decl_constant_value_safe (tree decl)
+{
+ return constant_value_1 (decl, /*integral_p=*/processing_template_decl,
+ /*return_aggregate_cst_ok_p=*/false);
}
\f
/* Common subroutines of build_new and build_vec_delete. */