public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108201] New: Warning about conversion from unsigned int to unsigned int
@ 2022-12-22 18:49 patrick.pelissier at gmail dot com
  2022-12-22 19:09 ` [Bug c/108201] " jakub at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: patrick.pelissier at gmail dot com @ 2022-12-22 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108201
           Summary: Warning about conversion from unsigned int to unsigned
                    int
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick.pelissier at gmail dot com
  Target Milestone: ---

On a Linux x86_64 system, with GCC 12.2.0, when I build the following program
with -Wsign-conversion , 


  typedef unsigned int m_string_unicode_t;

  void decode(char c, m_string_unicode_t *unicode) {
    *unicode = ((*unicode << 6)) | ((m_string_unicode_t) c);
  }

  void decode2(char c, unsigned int *unicode) {
    *unicode = ((*unicode << 6)) | ((unsigned int) c);
  }


I get the following wanning:


tst.c: In function 'decode':
tst.c:6:32: warning: conversion to 'm_string_unicode_t' {aka 'unsigned int'}
from 'unsigned int' may change the sign of the result [-Wsign-conversion]


There is a warning for the function decode, but not for the function decode2.

I don't understand the warning as there is no conversion from unsigned int to
unsigned int as both are the same type. I was expecting no warning for both
functions.

The warning only appears with GCC 12 (no issue with GCC 11).

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/108201] Warning about conversion from unsigned int to unsigned int
  2022-12-22 18:49 [Bug c/108201] New: Warning about conversion from unsigned int to unsigned int patrick.pelissier at gmail dot com
@ 2022-12-22 19:09 ` jakub at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-22 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I see the warning already in r0-88996 (haven't bisected exactly, r0-88387
didn't warn),
but before r10-6125-g731dbfc3f3b586e78f2ccdca24561ea3369c6338 the warning
looked like:
pr108201.c: In function ‘decode’:
pr108201.c:4:34: warning: conversion to ‘m_string_unicode_t’ {aka ‘unsigned
int’} from ‘char’ may change the sign of the result [-Wsign-conversion]
    4 |     *unicode = ((*unicode << 6)) | ((m_string_unicode_t) c);
      |                                  ^
and since then till latest trunk like:
pr108201.c: In function ‘decode’:
pr108201.c:4:34: warning: conversion to ‘m_string_unicode_t’ {aka ‘unsigned
int’} from ‘unsigned int’ may change the sign of the result [-Wsign-conversion]
    4 |     *unicode = ((*unicode << 6)) | ((m_string_unicode_t) c);
      |                                  ^

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-22 19:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-22 18:49 [Bug c/108201] New: Warning about conversion from unsigned int to unsigned int patrick.pelissier at gmail dot com
2022-12-22 19:09 ` [Bug c/108201] " jakub at gcc dot gnu.org

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).