[Bug c/108201] New: Warning about conversion from unsigned int to unsigned int

patrick.pelissier at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Dec 22 18:49:59 GMT 2022


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


More information about the Gcc-bugs mailing list