[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-07-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

--- Comment #8 from Marek Polacek  ---
Author: mpolacek
Date: Wed Jul 18 13:13:11 2018
New Revision: 262855

URL: https://gcc.gnu.org/viewcvs?rev=262855&root=gcc&view=rev
Log:
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.

Added:
trunk/gcc/testsuite/g++.dg/warn/Wsign-conversion-3.C
trunk/gcc/testsuite/g++.dg/warn/Wsign-conversion-4.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-07-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |6.5

[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-07-02 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-06-23 Thread TonyELewis at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

Tony E Lewis  changed:

   What|Removed |Added

 CC||TonyELewis at hotmail dot com

--- Comment #7 from Tony E Lewis  ---
I just hit this one yesterday (and am now disappointed to have missed being
able to contribute a new valid bug report by just 5 days :) ).

Thanks for the work that's already gone into addressing this.

The repro can be reduced slightly further by removing the struct:

typedef unsigned long sz_t;
sz_t s();
void f(int i) { s() < static_cast( i ); }

[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-06-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #6 from Marek Polacek  ---
The warning is produced in
 5350   if (! converted)
 5351 {
 5352   if (TREE_TYPE (op0) != result_type)
 5353 op0 = cp_convert_and_check (result_type, op0, complain);
 5354   if (TREE_TYPE (op1) != result_type)
 5355 op1 = cp_convert_and_check (result_type, op1, complain);
which we didn't enter before, because of this hunk:
@@ -5028,20 +5022,12 @@ cp_build_binary_op (location_t location,

   if (short_compare)
{
- /* Don't write &op0, etc., because that would prevent op0
-from being kept in a register.
-Instead, make copies of the our local variables and
-pass the copies by reference, then copy them back afterward.  */
- tree xop0 = op0, xop1 = op1, xresult_type = result_type;
+ /* We call shorten_compare only for diagnostic-reason.  */
+ tree xop0 = fold_simple (op0), xop1 = fold_simple (op1),
+  xresult_type = result_type;
  enum tree_code xresultcode = resultcode;
- tree val
-   = shorten_compare (location, &xop0, &xop1, &xresult_type,
+ shorten_compare (location, &xop0, &xop1, &xresult_type,
   &xresultcode);
- if (val != 0)
-   return cp_convert (boolean_type_node, val, complain);
- op0 = xop0, op1 = xop1;
- converted = 1;
- resultcode = xresultcode;
}

   if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)

so converted is now 0 whereas before it was 1.

[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-06-18 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

Jonathan Wakely  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #5 from Jonathan Wakely  ---
This regressed with r230365 "Merge C++ delayed folding branch."

[Bug c++/86190] [6/7/8/9 Regression] -Wsign-conversion ignores explicit conversion in some cases

2018-06-18 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

--- Comment #4 from Jonathan Wakely  ---
Further reduced:


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(var);
}


sc.cc: In function 'bool func(vector, int)':
sc.cc:10:23: warning: conversion to 'vector::size_type {aka long unsigned int}'
from 'int' may change the sign of the result [-Wsign-conversion]
   return vec.size() < static_cast(var);
   ^~~~

[Bug c++/86190] [6/7/8/9 Regression]-Wsign-conversion ignores explicit conversion in some cases

2018-06-18 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86190

Jonathan Wakely  changed:

   What|Removed |Added

 Status|WAITING |NEW
  Known to work||5.5.0
Summary|-Wsign-conversion ignores   |[6/7/8/9
   |explicit conversion in some |Regression]-Wsign-conversio
   |cases   |n ignores explicit
   ||conversion in some cases
  Known to fail||6.4.0, 7.3.0, 8.1.0, 9.0

--- Comment #3 from Jonathan Wakely  ---
The manual does say that an explicit cast should silence the warning. This is a
regression since GCC 5, and only seems to happen when there's an indirection
through a typedef:

using size_t = unsigned long;

template struct vector {
  using size_type = size_t;
  size_type size();
};

struct A
{
 int var;
 vector vec;

 bool func()
 {
  return vec.size() < static_cast(var);
 }
};

int main()
{
 A a;
 a.func();
}