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,7 +2346,7 @@ warnings_for_convert_and_check (tree type, tree expr, tree result) ...@@ -2344,7 +2346,7 @@ 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,7 +2359,7 @@ warnings_for_convert_and_check (tree type, tree expr, tree result) ...@@ -2357,7 +2359,7 @@ 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
...@@ -2365,7 +2367,7 @@ warnings_for_convert_and_check (tree type, tree expr, tree result) ...@@ -2365,7 +2367,7 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
} }
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,7 +3728,7 @@ build_integral_nontype_arg_conv (tree type, tree expr, tsubst_flags_t complain) ...@@ -3727,7 +3728,7 @@ 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. */
...@@ -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,7 +5939,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5937,7 +5939,7 @@ 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);
...@@ -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,7 +5991,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -5988,7 +5991,7 @@ 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;
} }
...@@ -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,7 +6080,7 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) ...@@ -6076,7 +6080,7 @@ 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);
...@@ -6089,7 +6093,7 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) ...@@ -6089,7 +6093,7 @@ 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);
} }
...@@ -6126,7 +6130,7 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) ...@@ -6126,7 +6130,7 @@ 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,7 +8559,7 @@ perform_implicit_conversion_flags (tree type, tree expr, ...@@ -8554,7 +8559,7 @@ 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,11 +8857,11 @@ initialize_reference (tree type, tree expr, ...@@ -8851,11 +8857,11 @@ 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));
} }
......
...@@ -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