Commit 76545796 by Paolo Carlini Committed by Paolo Carlini

call.c (build_conditional_expr_1, [...]): Protect error calls with complain & tf_error.

2013-04-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* call.c (build_conditional_expr_1, build_over_call): Protect
	error calls with complain & tf_error.
	* typeck.c (finish_class_member_access_expr, cp_build_binary_op,
	build_x_unary_op, cp_build_unary_op, cp_build_compound_expr,
	build_ptrmemfunc): Likewise.
	(lookup_destructor): Take tsubst_flags_t parameter, adjust.

	* cvt.c (warn_ref_binding): Rename to diagnose_ref_binding.
	(convert_to_reference): Adjust.

From-SVN: r197813
parent ffe0f557
2013-04-11 Paolo Carlini <paolo.carlini@oracle.com>
* call.c (build_conditional_expr_1, build_over_call): Protect
error calls with complain & tf_error.
* typeck.c (finish_class_member_access_expr, cp_build_binary_op,
build_x_unary_op, cp_build_unary_op, cp_build_compound_expr,
build_ptrmemfunc): Likewise.
(lookup_destructor): Take tsubst_flags_t parameter, adjust.
* cvt.c (warn_ref_binding): Rename to diagnose_ref_binding.
(convert_to_reference): Adjust.
2013-04-11 Jason Merrill <jason@redhat.com> 2013-04-11 Jason Merrill <jason@redhat.com>
* pt.c (tsubst_copy) [VAR_DECL]: Don't call tsubst for * pt.c (tsubst_copy) [VAR_DECL]: Don't call tsubst for
......
...@@ -4577,6 +4577,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tree arg3, ...@@ -4577,6 +4577,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tree arg3,
|| (conv2 && conv2->kind == ck_ambig) || (conv2 && conv2->kind == ck_ambig)
|| (conv3 && conv3->kind == ck_ambig)) || (conv3 && conv3->kind == ck_ambig))
{ {
if (complain & tf_error)
error ("operands to ?: have different types %qT and %qT", error ("operands to ?: have different types %qT and %qT",
arg2_type, arg3_type); arg2_type, arg3_type);
result = error_mark_node; result = error_mark_node;
...@@ -4760,6 +4761,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tree arg3, ...@@ -4760,6 +4761,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tree arg3,
/* In this case, there is always a common type. */ /* In this case, there is always a common type. */
result_type = type_after_usual_arithmetic_conversions (arg2_type, result_type = type_after_usual_arithmetic_conversions (arg2_type,
arg3_type); arg3_type);
if (complain & tf_warning)
do_warn_double_promotion (result_type, arg2_type, arg3_type, do_warn_double_promotion (result_type, arg2_type, arg3_type,
"implicit conversion from %qT to %qT to " "implicit conversion from %qT to %qT to "
"match other result of conditional", "match other result of conditional",
...@@ -6790,9 +6792,14 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) ...@@ -6790,9 +6792,14 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
/* Check that the base class is accessible. */ /* Check that the base class is accessible. */
if (!accessible_base_p (TREE_TYPE (argtype), if (!accessible_base_p (TREE_TYPE (argtype),
BINFO_TYPE (cand->conversion_path), true)) BINFO_TYPE (cand->conversion_path), true))
{
if (complain & tf_error)
error ("%qT is not an accessible base of %qT", error ("%qT is not an accessible base of %qT",
BINFO_TYPE (cand->conversion_path), BINFO_TYPE (cand->conversion_path),
TREE_TYPE (argtype)); TREE_TYPE (argtype));
else
return error_mark_node;
}
/* If fn was found by a using declaration, the conversion path /* If fn was found by a using declaration, the conversion path
will be to the derived class, not the base declaring fn. We will be to the derived class, not the base declaring fn. We
must convert from derived to base. */ must convert from derived to base. */
......
...@@ -40,7 +40,7 @@ static tree cp_convert_to_pointer (tree, tree, tsubst_flags_t); ...@@ -40,7 +40,7 @@ static tree cp_convert_to_pointer (tree, tree, tsubst_flags_t);
static tree convert_to_pointer_force (tree, tree, tsubst_flags_t); static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
static tree build_type_conversion (tree, tree); static tree build_type_conversion (tree, tree);
static tree build_up_reference (tree, tree, int, tree, tsubst_flags_t); static tree build_up_reference (tree, tree, int, tree, tsubst_flags_t);
static void warn_ref_binding (location_t, tree, tree, tree); static void diagnose_ref_binding (location_t, tree, tree, tree);
/* Change of width--truncation and extension of integers or reals-- /* Change of width--truncation and extension of integers or reals--
is represented with NOP_EXPR. Proper functioning of many things is represented with NOP_EXPR. Proper functioning of many things
...@@ -371,7 +371,7 @@ build_up_reference (tree type, tree arg, int flags, tree decl, ...@@ -371,7 +371,7 @@ build_up_reference (tree type, tree arg, int flags, tree decl,
non-volatile const type. */ non-volatile const type. */
static void static void
warn_ref_binding (location_t loc, tree reftype, tree intype, tree decl) diagnose_ref_binding (location_t loc, tree reftype, tree intype, tree decl)
{ {
tree ttl = TREE_TYPE (reftype); tree ttl = TREE_TYPE (reftype);
...@@ -456,9 +456,9 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -456,9 +456,9 @@ convert_to_reference (tree reftype, tree expr, int convtype,
tree ttl = TREE_TYPE (reftype); tree ttl = TREE_TYPE (reftype);
tree ttr = lvalue_type (expr); tree ttr = lvalue_type (expr);
if ((complain & tf_warning) if ((complain & tf_error)
&& ! real_lvalue_p (expr)) && ! real_lvalue_p (expr))
warn_ref_binding (loc, reftype, intype, decl); diagnose_ref_binding (loc, reftype, intype, decl);
if (! (convtype & CONV_CONST) if (! (convtype & CONV_CONST)
&& !at_least_as_qualified_p (ttl, ttr)) && !at_least_as_qualified_p (ttl, ttr))
...@@ -502,8 +502,8 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -502,8 +502,8 @@ convert_to_reference (tree reftype, tree expr, int convtype,
ICR_CONVERTING, 0, 0, complain); ICR_CONVERTING, 0, 0, complain);
if (rval == NULL_TREE || rval == error_mark_node) if (rval == NULL_TREE || rval == error_mark_node)
return rval; return rval;
if (complain & tf_warning) if (complain & tf_error)
warn_ref_binding (loc, reftype, intype, decl); diagnose_ref_binding (loc, reftype, intype, decl);
rval = build_up_reference (reftype, rval, flags, decl, complain); rval = build_up_reference (reftype, rval, flags, decl, complain);
} }
......
...@@ -54,7 +54,7 @@ static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t); ...@@ -54,7 +54,7 @@ static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t);
static void casts_away_constness_r (tree *, tree *, tsubst_flags_t); static void casts_away_constness_r (tree *, tree *, tsubst_flags_t);
static bool casts_away_constness (tree, tree, tsubst_flags_t); static bool casts_away_constness (tree, tree, tsubst_flags_t);
static void maybe_warn_about_returning_address_of_local (tree); static void maybe_warn_about_returning_address_of_local (tree);
static tree lookup_destructor (tree, tree, tree); static tree lookup_destructor (tree, tree, tree, tsubst_flags_t);
static void warn_args_num (location_t, tree, bool); static void warn_args_num (location_t, tree, bool);
static int convert_arguments (tree, vec<tree, va_gc> **, tree, int, static int convert_arguments (tree, vec<tree, va_gc> **, tree, int,
tsubst_flags_t); tsubst_flags_t);
...@@ -2469,7 +2469,8 @@ build_class_member_access_expr (tree object, tree member, ...@@ -2469,7 +2469,8 @@ build_class_member_access_expr (tree object, tree member,
SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type. */ SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type. */
static tree static tree
lookup_destructor (tree object, tree scope, tree dtor_name) lookup_destructor (tree object, tree scope, tree dtor_name,
tsubst_flags_t complain)
{ {
tree object_type = TREE_TYPE (object); tree object_type = TREE_TYPE (object);
tree dtor_type = TREE_OPERAND (dtor_name, 0); tree dtor_type = TREE_OPERAND (dtor_name, 0);
...@@ -2477,6 +2478,7 @@ lookup_destructor (tree object, tree scope, tree dtor_name) ...@@ -2477,6 +2478,7 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
if (scope && !check_dtor_name (scope, dtor_type)) if (scope && !check_dtor_name (scope, dtor_type))
{ {
if (complain & tf_error)
error ("qualified type %qT does not match destructor name ~%qT", error ("qualified type %qT does not match destructor name ~%qT",
scope, dtor_type); scope, dtor_type);
return error_mark_node; return error_mark_node;
...@@ -2489,6 +2491,7 @@ lookup_destructor (tree object, tree scope, tree dtor_name) ...@@ -2489,6 +2491,7 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
dtor_type = object_type; dtor_type = object_type;
else else
{ {
if (complain & tf_error)
error ("object type %qT does not match destructor name ~%qT", error ("object type %qT does not match destructor name ~%qT",
object_type, dtor_type); object_type, dtor_type);
return error_mark_node; return error_mark_node;
...@@ -2497,8 +2500,9 @@ lookup_destructor (tree object, tree scope, tree dtor_name) ...@@ -2497,8 +2500,9 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
} }
else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type))) else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
{ {
error ("the type being destroyed is %qT, but the destructor refers to %qT", if (complain & tf_error)
TYPE_MAIN_VARIANT (object_type), dtor_type); error ("the type being destroyed is %qT, but the destructor "
"refers to %qT", TYPE_MAIN_VARIANT (object_type), dtor_type);
return error_mark_node; return error_mark_node;
} }
expr = lookup_member (dtor_type, complete_dtor_identifier, expr = lookup_member (dtor_type, complete_dtor_identifier,
...@@ -2731,7 +2735,7 @@ finish_class_member_access_expr (tree object, tree name, bool template_p, ...@@ -2731,7 +2735,7 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
} }
if (TREE_CODE (name) == BIT_NOT_EXPR) if (TREE_CODE (name) == BIT_NOT_EXPR)
member = lookup_destructor (object, scope, name); member = lookup_destructor (object, scope, name, complain);
else else
{ {
/* Look up the member. */ /* Look up the member. */
...@@ -3933,6 +3937,7 @@ cp_build_binary_op (location_t location, ...@@ -3933,6 +3937,7 @@ cp_build_binary_op (location_t location,
if ((invalid_op_diag if ((invalid_op_diag
= targetm.invalid_binary_op (code, type0, type1))) = targetm.invalid_binary_op (code, type0, type1)))
{ {
if (complain & tf_error)
error (invalid_op_diag); error (invalid_op_diag);
return error_mark_node; return error_mark_node;
} }
...@@ -4600,6 +4605,7 @@ cp_build_binary_op (location_t location, ...@@ -4600,6 +4605,7 @@ cp_build_binary_op (location_t location,
|| !same_scalar_type_ignoring_signedness (TREE_TYPE (type0), || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
TREE_TYPE (type1))) TREE_TYPE (type1)))
{ {
if (complain & tf_error)
binary_op_error (location, code, type0, type1); binary_op_error (location, code, type0, type1);
return error_mark_node; return error_mark_node;
} }
...@@ -4612,6 +4618,7 @@ cp_build_binary_op (location_t location, ...@@ -4612,6 +4618,7 @@ cp_build_binary_op (location_t location,
&& (shorten || common || short_compare)) && (shorten || common || short_compare))
{ {
result_type = cp_common_type (type0, type1); result_type = cp_common_type (type0, type1);
if (complain & tf_warning)
do_warn_double_promotion (result_type, type0, type1, do_warn_double_promotion (result_type, type0, type1,
"implicit conversion from %qT to %qT " "implicit conversion from %qT to %qT "
"to match other operand of binary " "to match other operand of binary "
...@@ -4954,6 +4961,7 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg, ...@@ -4954,6 +4961,7 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
tree fn = get_first_fn (xarg); tree fn = get_first_fn (xarg);
if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn)) if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn))
{ {
if (complain & tf_error)
error (DECL_CONSTRUCTOR_P (fn) error (DECL_CONSTRUCTOR_P (fn)
? G_("taking address of constructor %qE") ? G_("taking address of constructor %qE")
: G_("taking address of destructor %qE"), : G_("taking address of destructor %qE"),
...@@ -4970,17 +4978,23 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg, ...@@ -4970,17 +4978,23 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
if (TREE_CODE (xarg) != OFFSET_REF if (TREE_CODE (xarg) != OFFSET_REF
|| !TYPE_P (TREE_OPERAND (xarg, 0))) || !TYPE_P (TREE_OPERAND (xarg, 0)))
{ {
error ("invalid use of %qE to form a pointer-to-member-function", if (complain & tf_error)
xarg); {
error ("invalid use of %qE to form a "
"pointer-to-member-function", xarg);
if (TREE_CODE (xarg) != OFFSET_REF) if (TREE_CODE (xarg) != OFFSET_REF)
inform (input_location, " a qualified-id is required"); inform (input_location, " a qualified-id is required");
}
return error_mark_node; return error_mark_node;
} }
else else
{ {
if (complain & tf_error)
error ("parentheses around %qE cannot be used to form a" error ("parentheses around %qE cannot be used to form a"
" pointer-to-member-function", " pointer-to-member-function",
xarg); xarg);
else
return error_mark_node;
PTRMEM_OK_P (xarg) = 1; PTRMEM_OK_P (xarg) = 1;
} }
} }
...@@ -5395,6 +5409,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, ...@@ -5395,6 +5409,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
: code), : code),
TREE_TYPE (xarg)))) TREE_TYPE (xarg))))
{ {
if (complain & tf_error)
error (invalid_op_diag); error (invalid_op_diag);
return error_mark_node; return error_mark_node;
} }
...@@ -6028,6 +6043,7 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain) ...@@ -6028,6 +6043,7 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
if (type_unknown_p (rhs)) if (type_unknown_p (rhs))
{ {
if (complain & tf_error)
error ("no context to resolve type of %qE", rhs); error ("no context to resolve type of %qE", rhs);
return error_mark_node; return error_mark_node;
} }
...@@ -7577,8 +7593,13 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p, ...@@ -7577,8 +7593,13 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p,
if (!force if (!force
&& !can_convert_arg (to_type, TREE_TYPE (pfn), pfn, && !can_convert_arg (to_type, TREE_TYPE (pfn), pfn,
LOOKUP_NORMAL, complain)) LOOKUP_NORMAL, complain))
{
if (complain & tf_error)
error ("invalid conversion to type %qT from type %qT", error ("invalid conversion to type %qT from type %qT",
to_type, pfn_type); to_type, pfn_type);
else
return error_mark_node;
}
n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type), n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type), TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
......
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