From dc88fc93b7fd42cb9b9602fa17dc17820bfd9717 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 1 Dec 2015 09:37:43 -0500 Subject: [PATCH 09/10] Fix g++.dg/warn/pr35635.C This testcase was broken by the patch kit; upon investigation the best fix is to try to use the location of the relevant expression when warning about conversions, rather than input_location, falling back to the latter via EXPR_LOC_OR_LOC. One dg-warning needed moving, since the caret is on the "?" of the conditional here: uchar_x = bar != 0 ~~~~~~~~ ? (unsigned char) 1024 ^~~~~~~~~~~~~~~~~~~~~~ : -1; ~~~~ gcc/cp/ChangeLog: * cvt.c (cp_convert_and_check): When warning about conversions, attempt to use the location of "expr" if available, otherwise falling back to the old behavior of using input_location. gcc/testsuite/ChangeLog: * g++.dg/warn/pr35635.C (func3): Update location of a dg-warning. --- gcc/cp/cvt.c | 4 ++-- gcc/testsuite/g++.dg/warn/pr35635.C | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index ebca004..f24f280 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -650,8 +650,8 @@ cp_convert_and_check (tree type, tree expr, tsubst_flags_t complain) folded_result = fold_simple (folded_result); if (!TREE_OVERFLOW_P (folded) && folded_result != error_mark_node) - warnings_for_convert_and_check (input_location, type, folded, - folded_result); + warnings_for_convert_and_check (EXPR_LOC_OR_LOC (expr, input_location), + type, folded, folded_result); } return result; diff --git a/gcc/testsuite/g++.dg/warn/pr35635.C b/gcc/testsuite/g++.dg/warn/pr35635.C index de68ceb..19345c5 100644 --- a/gcc/testsuite/g++.dg/warn/pr35635.C +++ b/gcc/testsuite/g++.dg/warn/pr35635.C @@ -62,9 +62,9 @@ void func3() /* At least one branch of ? does not fit in the destination, thus warn. */ uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */ - uchar_x = bar != 0 /* { dg-warning "negative integer implicitly converted to unsigned type" } */ - ? (unsigned char) 1024 - : -1; + uchar_x = bar != 0 + ? (unsigned char) 1024 /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + : -1; } void func4() -- 1.8.5.3