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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> Oops, I meant to say the warning was just suppressed for the += case, see PR
> 40752.

Rather, it was suppressed for the simple case where the RHS has a suitable
type.  As Jonathan says, (CHAR_BIT * static_cast<short>(i)) has type int (it
would be unsigned without the cast).  And then the << expression has type int. 
And then the | expression has type int.

Before the patch for 40752, we would warn based just on the type of the |
expression.  Now we also look at the type of the << expression, see that it is
also int, and warn.  You can avoid the warning by breaking up the expression
more:

#define CHAR_BIT 8
void print_byte_order( short )
{
   short val = 0;
   unsigned i = 1;
   short pat1 = (CHAR_BIT * static_cast<short>(i));
   short pat2 = pat1 << (CHAR_BIT * static_cast<short>(i));
   val |= pat2;
}

or adding another cast as in comment #1.

Perhaps I should adjust the 40752 patch to work recursively.

Reply via email to