public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/97833] New: -Wconversion behaves erratic
@ 2020-11-15  4:16 sven.koehler at gmail dot com
  0 siblings, 0 replies; only message in thread
From: sven.koehler at gmail dot com @ 2020-11-15  4:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97833
           Summary: -Wconversion behaves erratic
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sven.koehler at gmail dot com
  Target Milestone: ---

Created attachment 49559
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49559&action=edit
non-working example

Find attached an example for which -Wconversion behaves uncomprehensible.

Why does it yields warning for test2 but not for test1 and test3?
This happens with gcc for 32bit arm and gcc for x86_64.

In all 3 functions, we have 2 shift operations. The operand is uint16_t, which
is promoted to int. The result of the shift operations is cast to uint16_t. So
the operands of the bit-wise or are again uint16_t. So both operands of the
bitwise or are promoted to int.

So basically, in all 3 cases the code is returning an int. However, -W
conversion warns only in 1 case.

Also, why does it matter whether x is shifted by 0 or 1 ? Why does a shift by 0
result in an error, and a shift by 1 does not?

Why does it matter whether x and y are originally uint8_t being cast to
uint16_t (test2) or a uint16_t (test3) originally? In both cases, the result of
the shifts is cast to uint16_t.


Is gcc trying to keep track of the range of the individual expressions? Is gcc
somehow failing when the a shift by 0 occurs? I believe that a shift by zero is
defined behavior.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-15  4:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15  4:16 [Bug c/97833] New: -Wconversion behaves erratic sven.koehler at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).