if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
{
warn_for_address_of_packed_member (type, orig_rhs);
+ if (type != rhstype)
+ /* Convert RHS to TYPE in order to not lose TYPE in diagnostics. */
+ rhs = convert (type, rhs);
return rhs;
}
{
if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
conv->type = qualified_to;
+ else if (from != to)
+ /* Use TO in order to not lose TO in diagnostics. */
+ conv->type = to;
return conv;
}
static tree convert_like (conversion *, tree, tree, int, bool, bool, bool,
tsubst_flags_t);
+/* Adjust the result EXPR of a conversion to the expected type TOTYPE, which
+ must be equivalent but might be a typedef. */
+
+static tree
+maybe_adjust_type_name (tree type, tree expr, conversion_kind kind)
+{
+ if (expr == error_mark_node
+ || processing_template_decl)
+ return expr;
+
+ tree etype = TREE_TYPE (expr);
+ if (etype == type)
+ return expr;
+
+ gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p (etype, type)
+ || is_bitfield_expr_with_lowered_type (expr)
+ || seen_error ());
+
+ if (SCALAR_TYPE_P (type)
+ && (kind == ck_rvalue
+ /* ??? We should be able to do this for ck_identity of more prvalue
+ expressions, but checking !obvalue_p here breaks, so for now let's
+ just handle NON_LVALUE_EXPR (such as the location wrapper for a
+ literal). Maybe we want to express already-rvalue in the
+ conversion somehow? */
+ || TREE_CODE (expr) == NON_LVALUE_EXPR))
+ expr = build_nop (type, expr);
+
+ return expr;
+}
+
/* Perform the conversions in CONVS on the expression EXPR. FN and
ARGNUM are used for diagnostics. ARGNUM is zero based, -1
indicates the `this' argument of a method. INNER is nonzero when
continue to warn about uses of EXPR as an integer, rather than as a
pointer. */
expr = build_int_cst (totype, 0);
- return expr;
+ return maybe_adjust_type_name (totype, expr, convs->kind);
case ck_ambig:
/* We leave bad_p off ck_ambig because overload resolution considers
it valid, it just fails when we try to perform it. So we need to
return error_mark_node;
}
+ if ((complain & tf_warning) && fn
+ && warn_suggest_attribute_format)
+ {
+ tree rhstype = TREE_TYPE (expr);
+ const enum tree_code coder = TREE_CODE (rhstype);
+ const enum tree_code codel = TREE_CODE (totype);
+ if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
+ && coder == codel
+ && check_missing_format_attribute (totype, rhstype))
+ warning (OPT_Wsuggest_attribute_format,
+ "argument of function call might be a candidate "
+ "for a format attribute");
+ }
+
if (! MAYBE_CLASS_TYPE_P (totype))
- return expr;
+ return maybe_adjust_type_name (totype, expr, convs->kind);
/* Don't introduce copies when passing arguments along to the inherited
constructor. */
&& tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node)))
val = cp_perform_integral_promotions (val, complain);
if (complain & tf_warning)
- {
- if (warn_suggest_attribute_format)
- {
- tree rhstype = TREE_TYPE (val);
- const enum tree_code coder = TREE_CODE (rhstype);
- const enum tree_code codel = TREE_CODE (type);
- if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
- && coder == codel
- && check_missing_format_attribute (type, rhstype))
- warning (OPT_Wsuggest_attribute_format,
- "argument of function call might be a candidate "
- "for a format attribute");
- }
- maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
- }
+ maybe_warn_parm_abi (type, cp_expr_loc_or_input_loc (val));
if (complain & tf_warning)
warn_for_address_of_packed_member (type, val);
/* { dg-begin-multiline-output "" }
- ┌───────────────────────────────────────┐
- │ write of '(int) 42' │
- └───────────────────────────────────────┘
- │ │
- │ │
- v v
- â\94\8câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\90â\94\8c──────────────────┐
- │ buffer allocated on stack at (1) ││after valid range │
- â\94\94â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\98â\94\94──────────────────┘
- â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9c────────┬─────────┤
- │ │
- ╭────────────────┴───────────────╮ ╭─────────┴────────╮
- │capacity: '(size * 4) + 3' bytes│ │overflow of 1 byte│
- ╰────────────────────────────────╯ ╰──────────────────╯
+ ┌────────────────────────────────────────┐
+ │ write of '(int32_t) 42' │
+ └────────────────────────────────────────┘
+ │ │
+ │ │
+ v v
+ â\94\8câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\90 â\94\8câ\94\80──────────────────┐
+ │ buffer allocated on stack at (1) │ │ after valid range │
+ â\94\94â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\98 â\94\94â\94\80──────────────────┘
+ â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤ â\94\9câ\94\80────────┬─────────┤
+ │ │
+ ╭────────────────┴───────────────╮ ╭─────────┴────────╮
+ │capacity: '(size * 4) + 3' bytes│ │overflow of 1 byte│
+ ╰────────────────────────────────╯ ╰──────────────────╯
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
- ┌───────────────────┐
- │write of '(int) 42'│
- └───────────────────┘
- │
- │
- v
- ┌───────────────────────────────┐ ┌───────────────────┐
- │buffer allocated on heap at (1)│ │ after valid range │
- └───────────────────────────────┘ └───────────────────┘
- â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬─────────┤
- │ │ │
- ╭─────────────┴────────────╮ ╭───┴───╮ ╭─────────┴─────────╮
- │capacity: 'size * 4' bytes│ │4 bytes│ │overflow of 4 bytes│
- ╰──────────────────────────╯ ╰───────╯ ╰───────────────────╯
+ ┌───────────────────────┐
+ │write of '(int32_t) 42'│
+ └───────────────────────┘
+ │
+ │
+ v
+ ┌───────────────────────────────┐ ┌───────────────────────┐
+ │buffer allocated on heap at (1)│ │ after valid range │
+ └───────────────────────────────┘ └───────────────────────┘
+ â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80─────────┤
+ │ │ │
+ ╭─────────────┴────────────╮ ╭───┴───╮ ╭─────────┴─────────╮
+ │capacity: 'size * 4' bytes│ │4 bytes│ │overflow of 4 bytes│
+ ╰──────────────────────────╯ ╰───────╯ ╰───────────────────╯
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
- ┌───────────────────┐
- │write of '(int) 42'│
- └───────────────────┘
- │
- │
- v
- â\94\8câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\90 ┌────────────────────────────────┐
- │before valid range │ │buffer allocated on stack at (1)│
- â\94\94â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\98 └────────────────────────────────┘
- â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80─────┤├───────────────┬────────────────┤
- │ │ │
- ╭─────────┴───────────╮ ╭───┴───╮ ╭───────────┴───────────╮
- │underwrite of 4 bytes│ │4 bytes│ │capacity: 'n * 4' bytes│
- ╰─────────────────────╯ ╰───────╯ ╰───────────────────────╯
+ â\94\8câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\90
+ │write of '(int32_t) 42'│
+ â\94\94â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\98
+ │
+ │
+ v
+ â\94\8câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\90 ┌────────────────────────────────┐
+ │ before valid range │ │buffer allocated on stack at (1)│
+ â\94\94â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\98 └────────────────────────────────┘
+ â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤â\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94¬─────┤├───────────────┬────────────────┤
+ │ │ │
+ ╭──────────┴──────────╮ ╭───┴───╮ ╭───────────┴───────────╮
+ │underwrite of 4 bytes│ │4 bytes│ │capacity: 'n * 4' bytes│
+ ╰─────────────────────╯ ╰───────╯ ╰───────────────────────╯
{ dg-end-multiline-output "" } */