Commit c56e9727 by Marek Polacek Committed by Marek Polacek

PR c++/86190 - bogus -Wsign-conversion warning

	PR c++/86190 - bogus -Wsign-conversion warning
	* typeck.c (cp_build_binary_op): Fix formatting.  Add a warning
	sentinel.

	* g++.dg/warn/Wsign-conversion-3.C: New test.
	* g++.dg/warn/Wsign-conversion-4.C: New test.

From-SVN: r262855
parent eb592645
2018-07-18 Marek Polacek <polacek@redhat.com>
PR c++/86190 - bogus -Wsign-conversion warning
* typeck.c (cp_build_binary_op): Fix formatting. Add a warning
sentinel.
2018-07-18 Paolo Carlini <paolo.carlini@oracle.com> 2018-07-18 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59480, DR 136 PR c++/59480, DR 136
......
...@@ -5312,12 +5312,13 @@ cp_build_binary_op (location_t location, ...@@ -5312,12 +5312,13 @@ cp_build_binary_op (location_t location,
if (short_compare) if (short_compare)
{ {
/* We call shorten_compare only for diagnostic-reason. */ /* We call shorten_compare only for diagnostics. */
tree xop0 = fold_simple (op0), xop1 = fold_simple (op1), tree xop0 = fold_simple (op0);
xresult_type = result_type; tree xop1 = fold_simple (op1);
tree xresult_type = result_type;
enum tree_code xresultcode = resultcode; enum tree_code xresultcode = resultcode;
shorten_compare (location, &xop0, &xop1, &xresult_type, shorten_compare (location, &xop0, &xop1, &xresult_type,
&xresultcode); &xresultcode);
} }
if ((short_compare || code == MIN_EXPR || code == MAX_EXPR) if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
...@@ -5350,6 +5351,7 @@ cp_build_binary_op (location_t location, ...@@ -5350,6 +5351,7 @@ cp_build_binary_op (location_t location,
otherwise, it will be given type RESULT_TYPE. */ otherwise, it will be given type RESULT_TYPE. */
if (! converted) if (! converted)
{ {
warning_sentinel w (warn_sign_conversion, short_compare);
if (TREE_TYPE (op0) != result_type) if (TREE_TYPE (op0) != result_type)
op0 = cp_convert_and_check (result_type, op0, complain); op0 = cp_convert_and_check (result_type, op0, complain);
if (TREE_TYPE (op1) != result_type) if (TREE_TYPE (op1) != result_type)
......
2018-07-18 Marek Polacek <polacek@redhat.com>
PR c++/86190 - bogus -Wsign-conversion warning
* g++.dg/warn/Wsign-conversion-3.C: New test.
* g++.dg/warn/Wsign-conversion-4.C: New test.
2018-07-18 Paolo Carlini <paolo.carlini@oracle.com> 2018-07-18 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59480, DR 136 PR c++/59480, DR 136
......
// PR c++/86190
// { dg-options "-Wsign-conversion -Wsign-compare" }
typedef unsigned long sz_t;
sz_t s();
bool f(int i) { return s() < (unsigned long) i; }
bool f2(int i) { return s() < static_cast<unsigned long>(i); }
bool f3(int i) { return s() < i; } // { dg-warning "comparison of integer expressions of different signedness" }
bool f4(int i) { return s() < (long) i; } // { dg-warning "comparison of integer expressions of different signedness" }
bool f5(short int i) { return s() < (int) i; } // { dg-warning "comparison of integer expressions of different signedness" }
bool f6(signed char i) { return s() < (int) i; } // { dg-warning "comparison of integer expressions of different signedness" }
bool f7(unsigned char i) { return s() < i; }
bool f8(signed char i) { return s() < i; } // { dg-warning "comparison of integer expressions of different signedness" }
// PR c++/86190
// { dg-options "-Wsign-conversion -Wsign-compare" }
typedef unsigned long size_t;
struct vector {
typedef size_t size_type;
size_type size();
};
bool func(vector vec, int var)
{
return vec.size() < static_cast<size_t>(var); // { dg-bogus "may change" }
}
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