This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/70336] [5/6 regression] Incorrect Wconversion warning


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70336

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The above patch (untested so far) should get rid of the regression, thus we'd
warn exactly where 4.9 warned.
But, consider say:
void
f1 (unsigned char * x, int y, int z)
{
  x[z / 8] |= (unsigned char) (0x80 >> y);
}

unsigned char
f2 (unsigned char x, int y)
{
  x = x | (unsigned char) (0x80 >> y);
  return x;
}

unsigned char
f3 (unsigned char x, int y)
{
  x = x | (unsigned char) (y & 255);
  return x;
}

unsigned char
f4 (unsigned char x, int y)
{
  x = x | (unsigned char) (y & 127);
  return x;
}

unsigned char
f5 (unsigned char x, unsigned char y)
{
  x = x | (unsigned char) (y & 255);
  return x;
}

unsigned char
f6 (unsigned char x, int y)
{
  x = (unsigned char) (y & 255);
  return x;
}

void
f7 (unsigned char * x, int y, int z)
{
  x[z / 8] |= (0x80 >> y);
}

unsigned char
f8 (unsigned char x, int y)
{
  x = x | (0x80 >> y);
  return x;
}

unsigned char
f9 (unsigned char x, int y)
{
  x = x | (y & 255);
  return x;
}

unsigned char
f10 (unsigned char x, int y)
{
  x = x | (y & 127);
  return x;
}

unsigned char
f11 (unsigned char x, unsigned char y)
{
  x = x | (y & 255);
  return x;
}

unsigned char
f12 (unsigned char x, int y)
{
  x = (y & 255);
  return x;
}

Here -Wconversion will warn for many casesm even in 4.9, eventhough one could
argue that say in the f4 case nothing is lost during conversion, or that
without the explicit casts we should have known that nothing is altered during
the implicit conversions.  Which is why I've been talking about VRP, when we
start adding further and further cases where the implicit conversions can't
alter the values, we'll reimplement big part of VRP in the FEs.  And this has
nothing to do with not really delayed folding (even when both C and C++ FEs now
actually delay folding to some extents), to avoid the "false positives" from
-Wconversion you then want more folding rather than less folding.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]