Commit 5a3c9cf2 by Paolo Carlini Committed by Paolo Carlini

re PR c++/53158 ([C++11] Bogus error in loop condition)

/cp
2012-05-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53158
	* cvt.c (ocp_convert): Error out early for void -> bool conversions.
	* typeck.c (decay_conversion): Use error_at.
	* call.c (build_integral_nontype_arg_conv, convert_like_real,
	convert_arg_to_ellipsis, perform_implicit_conversion_flags,
	initialize_reference): Likewise.
	* cvt.c (warn_ref_binding): Add location_t parameter.
	(cp_convert_to_pointer, convert_to_reference, ocp_convert,
	convert_to_void, ): Use error_at and warning_at.

/c-family
2012-05-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53158
	* c-common.c (warnings_for_convert_and_check): Use warning_at.

/testsuite
2012-05-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53158
	* g++.dg/cpp0x/lambda/lambda-err2.C: New.
	* g++.dg/parse/error26.C: Tweak dg-error column number.

From-SVN: r187380
parent e5f13bf4
2012-05-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53158
* c-common.c (warnings_for_convert_and_check): Use warning_at.
2012-05-10 Richard Guenther <rguenther@suse.de> 2012-05-10 Richard Guenther <rguenther@suse.de>
* c-common.c (c_sizeof_or_alignof_type): Remove assert and * c-common.c (c_sizeof_or_alignof_type): Remove assert and
......
...@@ -2329,6 +2329,8 @@ conversion_warning (tree type, tree expr) ...@@ -2329,6 +2329,8 @@ conversion_warning (tree type, tree expr)
void void
warnings_for_convert_and_check (tree type, tree expr, tree result) warnings_for_convert_and_check (tree type, tree expr, tree result)
{ {
location_t loc = EXPR_LOC_OR_HERE (expr);
if (TREE_CODE (expr) == INTEGER_CST if (TREE_CODE (expr) == INTEGER_CST
&& (TREE_CODE (type) == INTEGER_TYPE && (TREE_CODE (type) == INTEGER_TYPE
|| TREE_CODE (type) == ENUMERAL_TYPE) || TREE_CODE (type) == ENUMERAL_TYPE)
...@@ -2344,8 +2346,8 @@ warnings_for_convert_and_check (tree type, tree expr, tree result) ...@@ -2344,8 +2346,8 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
/* This detects cases like converting -129 or 256 to /* This detects cases like converting -129 or 256 to
unsigned char. */ unsigned char. */
if (!int_fits_type_p (expr, c_common_signed_type (type))) if (!int_fits_type_p (expr, c_common_signed_type (type)))
warning (OPT_Woverflow, warning_at (loc, OPT_Woverflow,
"large integer implicitly truncated to unsigned type"); "large integer implicitly truncated to unsigned type");
else else
conversion_warning (type, expr); conversion_warning (type, expr);
} }
...@@ -2357,16 +2359,16 @@ warnings_for_convert_and_check (tree type, tree expr, tree result) ...@@ -2357,16 +2359,16 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
&& (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE
|| TYPE_PRECISION (TREE_TYPE (expr)) || TYPE_PRECISION (TREE_TYPE (expr))
!= TYPE_PRECISION (type))) != TYPE_PRECISION (type)))
warning (OPT_Woverflow, warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion"); "overflow in implicit constant conversion");
else else
conversion_warning (type, expr); conversion_warning (type, expr);
} }
else if ((TREE_CODE (result) == INTEGER_CST else if ((TREE_CODE (result) == INTEGER_CST
|| TREE_CODE (result) == FIXED_CST) && TREE_OVERFLOW (result)) || TREE_CODE (result) == FIXED_CST) && TREE_OVERFLOW (result))
warning (OPT_Woverflow, warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion"); "overflow in implicit constant conversion");
else else
conversion_warning (type, expr); conversion_warning (type, expr);
} }
......
2012-05-10 Paolo Carlini <paolo.carlini@oracle.com> 2012-05-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53158
* cvt.c (ocp_convert): Error out early for void -> bool conversions.
* typeck.c (decay_conversion): Use error_at.
* call.c (build_integral_nontype_arg_conv, convert_like_real,
convert_arg_to_ellipsis, perform_implicit_conversion_flags,
initialize_reference): Likewise.
* cvt.c (warn_ref_binding): Add location_t parameter.
(cp_convert_to_pointer, convert_to_reference, ocp_convert,
convert_to_void, ): Use error_at and warning_at.
2012-05-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53301 PR c++/53301
* decl.c (check_default_argument): Fix typo (POINTER_TYPE_P * decl.c (check_default_argument): Fix typo (POINTER_TYPE_P
instead of TYPE_PTR_P) in zero-as-null-pointer-constant warning. instead of TYPE_PTR_P) in zero-as-null-pointer-constant warning.
......
...@@ -3182,7 +3182,7 @@ print_z_candidate (const char *msgstr, struct z_candidate *candidate) ...@@ -3182,7 +3182,7 @@ print_z_candidate (const char *msgstr, struct z_candidate *candidate)
candidate->convs[0]->type); candidate->convs[0]->type);
} }
else if (TYPE_P (candidate->fn)) else if (TYPE_P (candidate->fn))
inform (input_location, "%s%T <conversion>", msg, candidate->fn); inform (loc, "%s%T <conversion>", msg, candidate->fn);
else if (candidate->viable == -1) else if (candidate->viable == -1)
inform (loc, "%s%#D <near match>", msg, candidate->fn); inform (loc, "%s%#D <near match>", msg, candidate->fn);
else if (DECL_DELETED_FN (STRIP_TEMPLATE (candidate->fn))) else if (DECL_DELETED_FN (STRIP_TEMPLATE (candidate->fn)))
...@@ -3692,6 +3692,7 @@ build_integral_nontype_arg_conv (tree type, tree expr, tsubst_flags_t complain) ...@@ -3692,6 +3692,7 @@ build_integral_nontype_arg_conv (tree type, tree expr, tsubst_flags_t complain)
conversion *conv; conversion *conv;
void *p; void *p;
tree t; tree t;
location_t loc = EXPR_LOC_OR_HERE (expr);
if (error_operand_p (expr)) if (error_operand_p (expr))
return error_mark_node; return error_mark_node;
...@@ -3727,8 +3728,8 @@ build_integral_nontype_arg_conv (tree type, tree expr, tsubst_flags_t complain) ...@@ -3727,8 +3728,8 @@ build_integral_nontype_arg_conv (tree type, tree expr, tsubst_flags_t complain)
break; break;
if (complain & tf_error) if (complain & tf_error)
error ("conversion from %qT to %qT not considered for " error_at (loc, "conversion from %qT to %qT not considered for "
"non-type template argument", t, type); "non-type template argument", t, type);
/* and fall through. */ /* and fall through. */
default: default:
...@@ -5648,6 +5649,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5648,6 +5649,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
tree totype = convs->type; tree totype = convs->type;
diagnostic_t diag_kind; diagnostic_t diag_kind;
int flags; int flags;
location_t loc = EXPR_LOC_OR_HERE (expr);
if (convs->bad_p && !(complain & tf_error)) if (convs->bad_p && !(complain & tf_error))
return error_mark_node; return error_mark_node;
...@@ -5668,13 +5670,13 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5668,13 +5670,13 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
&& SCALAR_TYPE_P (totype) && SCALAR_TYPE_P (totype)
&& CONSTRUCTOR_NELTS (expr) > 0 && CONSTRUCTOR_NELTS (expr) > 0
&& BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value)) && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
permerror (input_location, "too many braces around initializer for %qT", totype); permerror (loc, "too many braces around initializer for %qT", totype);
for (; t ; t = next_conversion (t)) for (; t ; t = next_conversion (t))
{ {
if (t->kind == ck_user && t->cand->reason) if (t->kind == ck_user && t->cand->reason)
{ {
permerror (input_location, "invalid user-defined conversion " permerror (loc, "invalid user-defined conversion "
"from %qT to %qT", TREE_TYPE (expr), totype); "from %qT to %qT", TREE_TYPE (expr), totype);
print_z_candidate ("candidate is:", t->cand); print_z_candidate ("candidate is:", t->cand);
expr = convert_like_real (t, expr, fn, argnum, 1, expr = convert_like_real (t, expr, fn, argnum, 1,
...@@ -5704,7 +5706,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5704,7 +5706,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
break; break;
} }
permerror (input_location, "invalid conversion from %qT to %qT", permerror (loc, "invalid conversion from %qT to %qT",
TREE_TYPE (expr), totype); TREE_TYPE (expr), totype);
if (fn) if (fn)
permerror (DECL_SOURCE_LOCATION (fn), permerror (DECL_SOURCE_LOCATION (fn),
...@@ -5937,8 +5939,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5937,8 +5939,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
gcc_assert (TYPE_REF_IS_RVALUE (ref_type) gcc_assert (TYPE_REF_IS_RVALUE (ref_type)
&& real_lvalue_p (expr)); && real_lvalue_p (expr));
error ("cannot bind %qT lvalue to %qT", error_at (loc, "cannot bind %qT lvalue to %qT",
TREE_TYPE (expr), totype); TREE_TYPE (expr), totype);
if (fn) if (fn)
error (" initializing argument %P of %q+D", argnum, fn); error (" initializing argument %P of %q+D", argnum, fn);
return error_mark_node; return error_mark_node;
...@@ -5969,13 +5971,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5969,13 +5971,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
/* If the reference is volatile or non-const, we /* If the reference is volatile or non-const, we
cannot create a temporary. */ cannot create a temporary. */
if (lvalue & clk_bitfield) if (lvalue & clk_bitfield)
error ("cannot bind bitfield %qE to %qT", error_at (loc, "cannot bind bitfield %qE to %qT",
expr, ref_type); expr, ref_type);
else if (lvalue & clk_packed) else if (lvalue & clk_packed)
error ("cannot bind packed field %qE to %qT", error_at (loc, "cannot bind packed field %qE to %qT",
expr, ref_type); expr, ref_type);
else else
error ("cannot bind rvalue %qE to %qT", expr, ref_type); error_at (loc, "cannot bind rvalue %qE to %qT",
expr, ref_type);
return error_mark_node; return error_mark_node;
} }
/* If the source is a packed field, and we must use a copy /* If the source is a packed field, and we must use a copy
...@@ -5988,8 +5991,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5988,8 +5991,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
&& CLASS_TYPE_P (type) && CLASS_TYPE_P (type)
&& type_has_nontrivial_copy_init (type)) && type_has_nontrivial_copy_init (type))
{ {
error ("cannot bind packed field %qE to %qT", error_at (loc, "cannot bind packed field %qE to %qT",
expr, ref_type); expr, ref_type);
return error_mark_node; return error_mark_node;
} }
if (lvalue & clk_bitfield) if (lvalue & clk_bitfield)
...@@ -6055,6 +6058,7 @@ tree ...@@ -6055,6 +6058,7 @@ tree
convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
{ {
tree arg_type; tree arg_type;
location_t loc = EXPR_LOC_OR_HERE (arg);
/* [expr.call] /* [expr.call]
...@@ -6076,10 +6080,10 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) ...@@ -6076,10 +6080,10 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
{ {
if ((complain & tf_warning) if ((complain & tf_warning)
&& warn_double_promotion && !c_inhibit_evaluation_warnings) && warn_double_promotion && !c_inhibit_evaluation_warnings)
warning (OPT_Wdouble_promotion, warning_at (loc, OPT_Wdouble_promotion,
"implicit conversion from %qT to %qT when passing " "implicit conversion from %qT to %qT when passing "
"argument to function", "argument to function",
arg_type, double_type_node); arg_type, double_type_node);
arg = convert_to_real (double_type_node, arg); arg = convert_to_real (double_type_node, arg);
} }
else if (NULLPTR_TYPE_P (arg_type)) else if (NULLPTR_TYPE_P (arg_type))
...@@ -6089,8 +6093,8 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) ...@@ -6089,8 +6093,8 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
if (SCOPED_ENUM_P (arg_type) && !abi_version_at_least (6)) if (SCOPED_ENUM_P (arg_type) && !abi_version_at_least (6))
{ {
if (complain & tf_warning) if (complain & tf_warning)
warning (OPT_Wabi, "scoped enum %qT will not promote to an " warning_at (loc, OPT_Wabi, "scoped enum %qT will not promote to an "
"integral type in a future version of GCC", arg_type); "integral type in a future version of GCC", arg_type);
arg = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg); arg = cp_convert (ENUM_UNDERLYING_TYPE (arg_type), arg);
} }
arg = perform_integral_promotions (arg); arg = perform_integral_promotions (arg);
...@@ -6126,8 +6130,8 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) ...@@ -6126,8 +6130,8 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
|| TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type)))
{ {
if (complain & tf_error) if (complain & tf_error)
error ("cannot pass objects of non-trivially-copyable " error_at (loc, "cannot pass objects of non-trivially-copyable "
"type %q#T through %<...%>", arg_type); "type %q#T through %<...%>", arg_type);
else else
return error_mark_node; return error_mark_node;
} }
...@@ -8532,6 +8536,7 @@ perform_implicit_conversion_flags (tree type, tree expr, ...@@ -8532,6 +8536,7 @@ perform_implicit_conversion_flags (tree type, tree expr,
{ {
conversion *conv; conversion *conv;
void *p; void *p;
location_t loc = EXPR_LOC_OR_HERE (expr);
if (error_operand_p (expr)) if (error_operand_p (expr))
return error_mark_node; return error_mark_node;
...@@ -8554,8 +8559,8 @@ perform_implicit_conversion_flags (tree type, tree expr, ...@@ -8554,8 +8559,8 @@ perform_implicit_conversion_flags (tree type, tree expr,
else if (invalid_nonstatic_memfn_p (expr, complain)) else if (invalid_nonstatic_memfn_p (expr, complain))
/* We gave an error. */; /* We gave an error. */;
else else
error ("could not convert %qE from %qT to %qT", expr, error_at (loc, "could not convert %qE from %qT to %qT", expr,
TREE_TYPE (expr), type); TREE_TYPE (expr), type);
} }
expr = error_mark_node; expr = error_mark_node;
} }
...@@ -8833,6 +8838,7 @@ initialize_reference (tree type, tree expr, ...@@ -8833,6 +8838,7 @@ initialize_reference (tree type, tree expr,
{ {
conversion *conv; conversion *conv;
void *p; void *p;
location_t loc = EXPR_LOC_OR_HERE (expr);
if (type == error_mark_node || error_operand_p (expr)) if (type == error_mark_node || error_operand_p (expr))
return error_mark_node; return error_mark_node;
...@@ -8851,13 +8857,13 @@ initialize_reference (tree type, tree expr, ...@@ -8851,13 +8857,13 @@ initialize_reference (tree type, tree expr,
else if (!CP_TYPE_CONST_P (TREE_TYPE (type)) else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
&& !TYPE_REF_IS_RVALUE (type) && !TYPE_REF_IS_RVALUE (type)
&& !real_lvalue_p (expr)) && !real_lvalue_p (expr))
error ("invalid initialization of non-const reference of " error_at (loc, "invalid initialization of non-const reference of "
"type %qT from an rvalue of type %qT", "type %qT from an rvalue of type %qT",
type, TREE_TYPE (expr)); type, TREE_TYPE (expr));
else else
error ("invalid initialization of reference of type " error_at (loc, "invalid initialization of reference of type "
"%qT from expression of type %qT", type, "%qT from expression of type %qT", type,
TREE_TYPE (expr)); TREE_TYPE (expr));
} }
return error_mark_node; return error_mark_node;
} }
......
...@@ -42,7 +42,7 @@ static tree cp_convert_to_pointer (tree, tree); ...@@ -42,7 +42,7 @@ static tree cp_convert_to_pointer (tree, tree);
static tree convert_to_pointer_force (tree, tree); static tree convert_to_pointer_force (tree, tree);
static tree build_type_conversion (tree, tree); static tree build_type_conversion (tree, tree);
static tree build_up_reference (tree, tree, int, tree); static tree build_up_reference (tree, tree, int, tree);
static void warn_ref_binding (tree, tree, tree); static void warn_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
...@@ -79,6 +79,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -79,6 +79,8 @@ cp_convert_to_pointer (tree type, tree expr)
tree intype = TREE_TYPE (expr); tree intype = TREE_TYPE (expr);
enum tree_code form; enum tree_code form;
tree rval; tree rval;
location_t loc = EXPR_LOC_OR_HERE (expr);
if (intype == error_mark_node) if (intype == error_mark_node)
return error_mark_node; return error_mark_node;
...@@ -87,8 +89,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -87,8 +89,8 @@ cp_convert_to_pointer (tree type, tree expr)
intype = complete_type (intype); intype = complete_type (intype);
if (!COMPLETE_TYPE_P (intype)) if (!COMPLETE_TYPE_P (intype))
{ {
error ("can%'t convert from incomplete type %qT to %qT", error_at (loc, "can%'t convert from incomplete type %qT to %qT",
intype, type); intype, type);
return error_mark_node; return error_mark_node;
} }
...@@ -96,8 +98,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -96,8 +98,8 @@ cp_convert_to_pointer (tree type, tree expr)
if (rval) if (rval)
{ {
if (rval == error_mark_node) if (rval == error_mark_node)
error ("conversion of %qE from %qT to %qT is ambiguous", error_at (loc, "conversion of %qE from %qT to %qT is ambiguous",
expr, intype, type); expr, intype, type);
return rval; return rval;
} }
} }
...@@ -166,8 +168,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -166,8 +168,8 @@ cp_convert_to_pointer (tree type, tree expr)
if (TYPE_PTRMEMFUNC_P (type)) if (TYPE_PTRMEMFUNC_P (type))
{ {
error ("cannot convert %qE from type %qT to type %qT", error_at (loc, "cannot convert %qE from type %qT to type %qT",
expr, intype, type); expr, intype, type);
return error_mark_node; return error_mark_node;
} }
...@@ -192,8 +194,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -192,8 +194,8 @@ cp_convert_to_pointer (tree type, tree expr)
tf_warning_or_error); tf_warning_or_error);
} }
} }
error ("cannot convert %qE from type %qT to type %qT", error_at (loc, "cannot convert %qE from type %qT to type %qT",
expr, intype, type); expr, intype, type);
return error_mark_node; return error_mark_node;
} }
...@@ -201,8 +203,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -201,8 +203,8 @@ cp_convert_to_pointer (tree type, tree expr)
{ {
if (c_inhibit_evaluation_warnings == 0 if (c_inhibit_evaluation_warnings == 0
&& !NULLPTR_TYPE_P (TREE_TYPE (expr))) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
warning (OPT_Wzero_as_null_pointer_constant, warning_at (loc, OPT_Wzero_as_null_pointer_constant,
"zero as null pointer constant"); "zero as null pointer constant");
if (TYPE_PTRMEMFUNC_P (type)) if (TYPE_PTRMEMFUNC_P (type))
return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0, return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
...@@ -221,7 +223,7 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -221,7 +223,7 @@ cp_convert_to_pointer (tree type, tree expr)
} }
else if (TYPE_PTR_TO_MEMBER_P (type) && INTEGRAL_CODE_P (form)) else if (TYPE_PTR_TO_MEMBER_P (type) && INTEGRAL_CODE_P (form))
{ {
error ("invalid conversion from %qT to %qT", intype, type); error_at (loc, "invalid conversion from %qT to %qT", intype, type);
return error_mark_node; return error_mark_node;
} }
...@@ -242,8 +244,8 @@ cp_convert_to_pointer (tree type, tree expr) ...@@ -242,8 +244,8 @@ cp_convert_to_pointer (tree type, tree expr)
if (type_unknown_p (expr)) if (type_unknown_p (expr))
return instantiate_type (type, expr, tf_warning_or_error); return instantiate_type (type, expr, tf_warning_or_error);
error ("cannot convert %qE from type %qT to type %qT", error_at (loc, "cannot convert %qE from type %qT to type %qT",
expr, intype, type); expr, intype, type);
return error_mark_node; return error_mark_node;
} }
...@@ -367,7 +369,7 @@ build_up_reference (tree type, tree arg, int flags, tree decl) ...@@ -367,7 +369,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 (tree reftype, tree intype, tree decl) warn_ref_binding (location_t loc, tree reftype, tree intype, tree decl)
{ {
tree ttl = TREE_TYPE (reftype); tree ttl = TREE_TYPE (reftype);
...@@ -388,7 +390,7 @@ warn_ref_binding (tree reftype, tree intype, tree decl) ...@@ -388,7 +390,7 @@ warn_ref_binding (tree reftype, tree intype, tree decl)
msg = G_("conversion to non-const reference type %q#T from " msg = G_("conversion to non-const reference type %q#T from "
"rvalue of type %qT"); "rvalue of type %qT");
permerror (input_location, msg, reftype, intype); permerror (loc, msg, reftype, intype);
} }
} }
...@@ -410,6 +412,7 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -410,6 +412,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
bool can_convert_intype_to_type; bool can_convert_intype_to_type;
tsubst_flags_t complain = ((flags & LOOKUP_COMPLAIN) tsubst_flags_t complain = ((flags & LOOKUP_COMPLAIN)
? tf_warning_or_error : tf_none); ? tf_warning_or_error : tf_none);
location_t loc = EXPR_LOC_OR_HERE (expr);
if (TREE_CODE (type) == FUNCTION_TYPE if (TREE_CODE (type) == FUNCTION_TYPE
&& TREE_TYPE (expr) == unknown_type_node) && TREE_TYPE (expr) == unknown_type_node)
...@@ -455,11 +458,11 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -455,11 +458,11 @@ convert_to_reference (tree reftype, tree expr, int convtype,
tree ttr = lvalue_type (expr); tree ttr = lvalue_type (expr);
if (! real_lvalue_p (expr)) if (! real_lvalue_p (expr))
warn_ref_binding (reftype, intype, decl); warn_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))
permerror (input_location, "conversion from %qT to %qT discards qualifiers", permerror (loc, "conversion from %qT to %qT discards qualifiers",
ttr, reftype); ttr, reftype);
} }
...@@ -477,8 +480,8 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -477,8 +480,8 @@ convert_to_reference (tree reftype, tree expr, int convtype,
if (TREE_CODE (intype) == POINTER_TYPE if (TREE_CODE (intype) == POINTER_TYPE
&& (comptypes (TREE_TYPE (intype), type, && (comptypes (TREE_TYPE (intype), type,
COMPARE_BASE | COMPARE_DERIVED))) COMPARE_BASE | COMPARE_DERIVED)))
warning (0, "casting %qT to %qT does not dereference pointer", warning_at (loc, 0, "casting %qT to %qT does not dereference pointer",
intype, reftype); intype, reftype);
rval = cp_build_addr_expr (expr, tf_warning_or_error); rval = cp_build_addr_expr (expr, tf_warning_or_error);
if (rval != error_mark_node) if (rval != error_mark_node)
...@@ -494,7 +497,7 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -494,7 +497,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
tf_warning_or_error); tf_warning_or_error);
if (rval == NULL_TREE || rval == error_mark_node) if (rval == NULL_TREE || rval == error_mark_node)
return rval; return rval;
warn_ref_binding (reftype, intype, decl); warn_ref_binding (loc, reftype, intype, decl);
rval = build_up_reference (reftype, rval, flags, decl); rval = build_up_reference (reftype, rval, flags, decl);
} }
...@@ -505,7 +508,7 @@ convert_to_reference (tree reftype, tree expr, int convtype, ...@@ -505,7 +508,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
} }
if (flags & LOOKUP_COMPLAIN) if (flags & LOOKUP_COMPLAIN)
error ("cannot convert type %qT to type %qT", intype, reftype); error_at (loc, "cannot convert type %qT to type %qT", intype, reftype);
return error_mark_node; return error_mark_node;
} }
...@@ -633,6 +636,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -633,6 +636,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
enum tree_code code = TREE_CODE (type); enum tree_code code = TREE_CODE (type);
const char *invalid_conv_diag; const char *invalid_conv_diag;
tree e1; tree e1;
location_t loc = EXPR_LOC_OR_HERE (expr);
if (error_operand_p (e) || type == error_mark_node) if (error_operand_p (e) || type == error_mark_node)
return error_mark_node; return error_mark_node;
...@@ -711,8 +715,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -711,8 +715,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
|| TREE_CODE (intype) == POINTER_TYPE) || TREE_CODE (intype) == POINTER_TYPE)
{ {
if (flags & LOOKUP_COMPLAIN) if (flags & LOOKUP_COMPLAIN)
permerror (input_location, "conversion from %q#T to %q#T", intype, type); permerror (loc, "conversion from %q#T to %q#T", intype, type);
if (!flag_permissive) if (!flag_permissive)
return error_mark_node; return error_mark_node;
} }
...@@ -726,10 +729,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -726,10 +729,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
unspecified. */ unspecified. */
if (TREE_CODE (expr) == INTEGER_CST if (TREE_CODE (expr) == INTEGER_CST
&& !int_fits_type_p (expr, ENUM_UNDERLYING_TYPE (type))) && !int_fits_type_p (expr, ENUM_UNDERLYING_TYPE (type)))
warning (OPT_Wconversion, warning_at (loc, OPT_Wconversion,
"the result of the conversion is unspecified because " "the result of the conversion is unspecified because "
"%qE is outside the range of type %qT", "%qE is outside the range of type %qT",
expr, type); expr, type);
} }
if (MAYBE_CLASS_TYPE_P (intype)) if (MAYBE_CLASS_TYPE_P (intype))
{ {
...@@ -738,11 +741,18 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -738,11 +741,18 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
if (rval) if (rval)
return rval; return rval;
if (flags & LOOKUP_COMPLAIN) if (flags & LOOKUP_COMPLAIN)
error ("%q#T used where a %qT was expected", intype, type); error_at (loc, "%q#T used where a %qT was expected", intype, type);
return error_mark_node; return error_mark_node;
} }
if (code == BOOLEAN_TYPE) if (code == BOOLEAN_TYPE)
{ {
if (TREE_CODE (intype) == VOID_TYPE)
{
error_at (loc, "could not convert %qE from %<void%> to %<bool%>",
expr);
return error_mark_node;
}
/* We can't implicitly convert a scoped enum to bool, so convert /* We can't implicitly convert a scoped enum to bool, so convert
to the underlying type first. */ to the underlying type first. */
if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
...@@ -769,7 +779,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -769,7 +779,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
if (ret_val) if (ret_val)
return ret_val; return ret_val;
if (flags & LOOKUP_COMPLAIN) if (flags & LOOKUP_COMPLAIN)
error ("%q#T used where a %qT was expected", in_vtype, type); error_at (loc, "%q#T used where a %qT was expected", in_vtype, type);
return error_mark_node; return error_mark_node;
} }
return fold_if_not_in_template (convert_to_vector (type, e)); return fold_if_not_in_template (convert_to_vector (type, e));
...@@ -784,7 +794,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -784,7 +794,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
return rval; return rval;
else else
if (flags & LOOKUP_COMPLAIN) if (flags & LOOKUP_COMPLAIN)
error ("%q#T used where a floating point value was expected", error_at (loc, "%q#T used where a floating point value was expected",
TREE_TYPE (e)); TREE_TYPE (e));
} }
if (code == REAL_TYPE) if (code == REAL_TYPE)
...@@ -845,8 +855,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -845,8 +855,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
if (invalid_nonstatic_memfn_p (expr, tf_warning_or_error)) if (invalid_nonstatic_memfn_p (expr, tf_warning_or_error))
/* We displayed the error message. */; /* We displayed the error message. */;
else else
error ("conversion from %qT to non-scalar type %qT requested", error_at (loc, "conversion from %qT to non-scalar type %qT requested",
TREE_TYPE (expr), type); TREE_TYPE (expr), type);
} }
return error_mark_node; return error_mark_node;
} }
...@@ -873,6 +883,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -873,6 +883,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
tree tree
convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
{ {
location_t loc = EXPR_LOC_OR_HERE (expr);
if (expr == error_mark_node if (expr == error_mark_node
|| TREE_TYPE (expr) == error_mark_node) || TREE_TYPE (expr) == error_mark_node)
return error_mark_node; return error_mark_node;
...@@ -903,7 +915,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -903,7 +915,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR) if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
{ {
if (complain & tf_error) if (complain & tf_error)
error ("pseudo-destructor is not called"); error_at (loc, "pseudo-destructor is not called");
return error_mark_node; return error_mark_node;
} }
if (VOID_TYPE_P (TREE_TYPE (expr))) if (VOID_TYPE_P (TREE_TYPE (expr)))
...@@ -980,35 +992,35 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -980,35 +992,35 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_CAST: case ICV_CAST:
warning (0, "conversion to void will not access " warning_at (loc, 0, "conversion to void will not access "
"object of incomplete type %qT", type); "object of incomplete type %qT", type);
break; break;
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"incomplete type %qT in second operand " "incomplete type %qT in second operand "
"of conditional expression", type); "of conditional expression", type);
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"incomplete type %qT in third operand " "incomplete type %qT in third operand "
"of conditional expression", type); "of conditional expression", type);
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"incomplete type %qT in right operand of " "incomplete type %qT in right operand of "
"comma operator", type); "comma operator", type);
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"incomplete type %qT in left operand of " "incomplete type %qT in left operand of "
"comma operator", type); "comma operator", type);
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"incomplete type %qT in statement", type); "incomplete type %qT in statement", type);
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"incomplete type %qT in for increment " "incomplete type %qT in for increment "
"expression", type); "expression", type);
break; break;
...@@ -1024,37 +1036,37 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1024,37 +1036,37 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_CAST: case ICV_CAST:
warning (0, "conversion to void will not access " warning_at (loc, 0, "conversion to void will not access "
"object of type %qT", type); "object of type %qT", type);
break; break;
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
warning (0, "implicit dereference will not access object " warning_at (loc, 0, "implicit dereference will not access "
"of type %qT in second operand of " "object of type %qT in second operand of "
"conditional expression", type); "conditional expression", type);
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
warning (0, "implicit dereference will not access object " warning_at (loc, 0, "implicit dereference will not access "
"of type %qT in third operand of " "object of type %qT in third operand of "
"conditional expression", type); "conditional expression", type);
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
warning (0, "implicit dereference will not access object " warning_at (loc, 0, "implicit dereference will not access "
"of type %qT in right operand of " "object of type %qT in right operand of "
"comma operator", type); "comma operator", type);
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
warning (0, "implicit dereference will not access object " warning_at (loc, 0, "implicit dereference will not access "
"of type %qT in left operand of comma operator", "object of type %qT in left operand of comma "
type); "operator", type);
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
warning (0, "implicit dereference will not access object " warning_at (loc, 0, "implicit dereference will not access "
"of type %qT in statement", type); "object of type %qT in statement", type);
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
warning (0, "implicit dereference will not access object " warning_at (loc, 0, "implicit dereference will not access "
"of type %qT in for increment expression", "object of type %qT in for increment expression",
type); type);
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
...@@ -1066,37 +1078,37 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1066,37 +1078,37 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_CAST: case ICV_CAST:
warning (0, "conversion to void will not access " warning_at (loc, 0, "conversion to void will not access "
"object of non-trivially-copyable type %qT", "object of non-trivially-copyable type %qT",
type); type);
break; break;
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"non-trivially-copyable type %qT in second " "non-trivially-copyable type %qT in second "
"operand of conditional expression", type); "operand of conditional expression", type);
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"non-trivially-copyable type %qT in third " "non-trivially-copyable type %qT in third "
"operand of conditional expression", type); "operand of conditional expression", type);
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"non-trivially-copyable type %qT in right " "non-trivially-copyable type %qT in right "
"operand of comma operator", type); "operand of comma operator", type);
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"non-trivially-copyable type %qT in left " "non-trivially-copyable type %qT in left "
"operand of comma operator", type); "operand of comma operator", type);
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"non-trivially-copyable type %qT in statement", "non-trivially-copyable type %qT in statement",
type); type);
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
warning (0, "indirection will not access object of " warning_at (loc, 0, "indirection will not access object of "
"non-trivially-copyable type %qT in for " "non-trivially-copyable type %qT in for "
"increment expression", type); "increment expression", type);
break; break;
...@@ -1117,7 +1129,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1117,7 +1129,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
&& (complain & tf_warning) && (complain & tf_warning)
&& !TREE_NO_WARNING (expr) && !TREE_NO_WARNING (expr)
&& !is_reference) && !is_reference)
warning (OPT_Wunused_value, "value computed is not used"); warning_at (loc, OPT_Wunused_value, "value computed is not used");
expr = TREE_OPERAND (expr, 0); expr = TREE_OPERAND (expr, 0);
} }
...@@ -1134,37 +1146,37 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1134,37 +1146,37 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_CAST: case ICV_CAST:
warning (0, "conversion to void will not access " warning_at (loc, 0, "conversion to void will not access "
"object %qE of incomplete type %qT", expr, type); "object %qE of incomplete type %qT", expr, type);
break; break;
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
warning (0, "variable %qE of incomplete type %qT will not " warning_at (loc, 0, "variable %qE of incomplete type %qT will "
"be accessed in second operand of " "not be accessed in second operand of "
"conditional expression", expr, type); "conditional expression", expr, type);
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
warning (0, "variable %qE of incomplete type %qT will not " warning_at (loc, 0, "variable %qE of incomplete type %qT will "
"be accessed in third operand of " "not be accessed in third operand of "
"conditional expression", expr, type); "conditional expression", expr, type);
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
warning (0, "variable %qE of incomplete type %qT will not " warning_at (loc, 0, "variable %qE of incomplete type %qT will "
"be accessed in right operand of comma operator", "not be accessed in right operand of comma operator",
expr, type); expr, type);
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
warning (0, "variable %qE of incomplete type %qT will not " warning_at (loc, 0, "variable %qE of incomplete type %qT will "
"be accessed in left operand of comma operator", "not be accessed in left operand of comma operator",
expr, type); expr, type);
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
warning (0, "variable %qE of incomplete type %qT will not " warning_at (loc, 0, "variable %qE of incomplete type %qT will "
"be accessed in statement", expr, type); "not be accessed in statement", expr, type);
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
warning (0, "variable %qE of incomplete type %qT will not " warning_at (loc, 0, "variable %qE of incomplete type %qT will "
"be accessed in for increment expression", "not be accessed in for increment expression",
expr, type); expr, type);
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
...@@ -1211,32 +1223,32 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1211,32 +1223,32 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_CAST: case ICV_CAST:
error ("conversion to void " error_at (loc, "conversion to void "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
error ("second operand of conditional expression " error_at (loc, "second operand of conditional expression "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
error ("third operand of conditional expression " error_at (loc, "third operand of conditional expression "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
error ("right operand of comma operator " error_at (loc, "right operand of comma operator "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
error ("left operand of comma operator " error_at (loc, "left operand of comma operator "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
error ("statement " error_at (loc, "statement "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
error ("for increment expression " error_at (loc, "for increment expression "
"cannot resolve address of overloaded function"); "cannot resolve address of overloaded function");
break; break;
} }
else else
...@@ -1250,34 +1262,34 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1250,34 +1262,34 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
warning (OPT_Waddress, warning_at (loc, OPT_Waddress,
"second operand of conditional expression " "second operand of conditional expression "
"is a reference, not call, to function %qE", expr); "is a reference, not call, to function %qE", expr);
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
warning (OPT_Waddress, warning_at (loc, OPT_Waddress,
"third operand of conditional expression " "third operand of conditional expression "
"is a reference, not call, to function %qE", expr); "is a reference, not call, to function %qE", expr);
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
warning (OPT_Waddress, warning_at (loc, OPT_Waddress,
"right operand of comma operator " "right operand of comma operator "
"is a reference, not call, to function %qE", expr); "is a reference, not call, to function %qE", expr);
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
warning (OPT_Waddress, warning_at (loc, OPT_Waddress,
"left operand of comma operator " "left operand of comma operator "
"is a reference, not call, to function %qE", expr); "is a reference, not call, to function %qE", expr);
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
warning (OPT_Waddress, warning_at (loc, OPT_Waddress,
"statement is a reference, not call, to function %qE", "statement is a reference, not call, to function %qE",
expr); expr);
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
warning (OPT_Waddress, warning_at (loc, OPT_Waddress,
"for increment expression " "for increment expression "
"is a reference, not call, to function %qE", expr); "is a reference, not call, to function %qE", expr);
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
...@@ -1302,28 +1314,30 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1302,28 +1314,30 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
switch (implicit) switch (implicit)
{ {
case ICV_SECOND_OF_COND: case ICV_SECOND_OF_COND:
warning (OPT_Wunused_value, warning_at (loc, OPT_Wunused_value,
"second operand of conditional expression has no effect"); "second operand of conditional expression "
"has no effect");
break; break;
case ICV_THIRD_OF_COND: case ICV_THIRD_OF_COND:
warning (OPT_Wunused_value, warning_at (loc, OPT_Wunused_value,
"third operand of conditional expression has no effect"); "third operand of conditional expression "
"has no effect");
break; break;
case ICV_RIGHT_OF_COMMA: case ICV_RIGHT_OF_COMMA:
warning (OPT_Wunused_value, warning_at (loc, OPT_Wunused_value,
"right operand of comma operator has no effect"); "right operand of comma operator has no effect");
break; break;
case ICV_LEFT_OF_COMMA: case ICV_LEFT_OF_COMMA:
warning (OPT_Wunused_value, warning_at (loc, OPT_Wunused_value,
"left operand of comma operator has no effect"); "left operand of comma operator has no effect");
break; break;
case ICV_STATEMENT: case ICV_STATEMENT:
warning (OPT_Wunused_value, warning_at (loc, OPT_Wunused_value,
"statement has no effect"); "statement has no effect");
break; break;
case ICV_THIRD_IN_FOR: case ICV_THIRD_IN_FOR:
warning (OPT_Wunused_value, warning_at (loc, OPT_Wunused_value,
"for increment expression has no effect"); "for increment expression has no effect");
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
...@@ -1361,7 +1375,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) ...@@ -1361,7 +1375,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
|| code == POSTDECREMENT_EXPR || code == POSTDECREMENT_EXPR
|| code == POSTINCREMENT_EXPR))) || code == POSTINCREMENT_EXPR)))
&& (complain & tf_warning)) && (complain & tf_warning))
warning (OPT_Wunused_value, "value computed is not used"); warning_at (loc, OPT_Wunused_value, "value computed is not used");
} }
} }
expr = build1 (CONVERT_EXPR, void_type_node, expr); expr = build1 (CONVERT_EXPR, void_type_node, expr);
......
...@@ -1822,6 +1822,7 @@ decay_conversion (tree exp, tsubst_flags_t complain) ...@@ -1822,6 +1822,7 @@ decay_conversion (tree exp, tsubst_flags_t complain)
{ {
tree type; tree type;
enum tree_code code; enum tree_code code;
location_t loc = EXPR_LOC_OR_HERE (exp);
type = TREE_TYPE (exp); type = TREE_TYPE (exp);
if (type == error_mark_node) if (type == error_mark_node)
...@@ -1853,7 +1854,7 @@ decay_conversion (tree exp, tsubst_flags_t complain) ...@@ -1853,7 +1854,7 @@ decay_conversion (tree exp, tsubst_flags_t complain)
if (code == VOID_TYPE) if (code == VOID_TYPE)
{ {
if (complain & tf_error) if (complain & tf_error)
error ("void value not ignored as it ought to be"); error_at (loc, "void value not ignored as it ought to be");
return error_mark_node; return error_mark_node;
} }
if (invalid_nonstatic_memfn_p (exp, complain)) if (invalid_nonstatic_memfn_p (exp, complain))
...@@ -1882,7 +1883,7 @@ decay_conversion (tree exp, tsubst_flags_t complain) ...@@ -1882,7 +1883,7 @@ decay_conversion (tree exp, tsubst_flags_t complain)
&& ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp))) && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
{ {
if (complain & tf_error) if (complain & tf_error)
error ("invalid use of non-lvalue array"); error_at (loc, "invalid use of non-lvalue array");
return error_mark_node; return error_mark_node;
} }
......
2012-05-10 Paolo Carlini <paolo.carlini@oracle.com> 2012-05-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53158
* g++.dg/cpp0x/lambda/lambda-err2.C: New.
* g++.dg/parse/error26.C: Tweak dg-error column number.
2012-05-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53301 PR c++/53301
* g++.dg/warn/Wzero-as-null-pointer-constant-6.C: New. * g++.dg/warn/Wzero-as-null-pointer-constant-6.C: New.
......
// PR c++/53158
// { dg-do compile { target c++11 } }
int main()
{
auto a = []() { return true; };
auto b = []() { return a(); }; // { dg-error "'a' is not captured" }
int c, d;
while (b() && c < d) // { dg-error "could not convert" }
{
}
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
void foo() void foo()
{ {
if (({int c[2];})) ; // { dg-error "7:ISO C.. forbids" "7" } if (({int c[2];})) ; // { dg-error "7:ISO C.. forbids" "7" }
// { dg-error "20:could not convert" "20" { target *-*-* } 6 } // { dg-error "17:could not convert" "17" { target *-*-* } 6 }
} }
void bar() void bar()
......
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