+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>
PR c++/59480, DR 136
if (short_compare)
{
- /* We call shorten_compare only for diagnostic-reason. */
- tree xop0 = fold_simple (op0), xop1 = fold_simple (op1),
- xresult_type = result_type;
+ /* We call shorten_compare only for diagnostics. */
+ tree xop0 = fold_simple (op0);
+ tree xop1 = fold_simple (op1);
+ tree xresult_type = result_type;
enum tree_code xresultcode = resultcode;
shorten_compare (location, &xop0, &xop1, &xresult_type,
- &xresultcode);
+ &xresultcode);
}
if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
otherwise, it will be given type RESULT_TYPE. */
if (! converted)
{
+ warning_sentinel w (warn_sign_conversion, short_compare);
if (TREE_TYPE (op0) != result_type)
op0 = cp_convert_and_check (result_type, op0, complain);
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>
PR c++/59480, DR 136
--- /dev/null
+// 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" }
--- /dev/null
+// 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" }
+}