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/21962] 4.0/4.1 Regression] ] format '%012llx' expects type X, but argument has type X


------- Additional Comments From joseph at codesourcery dot com  2005-06-08 16:32 -------
Subject: Re:  New: [bogus warning] format '%012llx' expects type
 X, but argument has type X

On Wed, 8 Jun 2005, pluto at agmk dot net wrote:

> extern void print(const char *my_format, ...)
> __attribute__((format(printf, 1, 2)));
> 
> typedef struct {
>     unsigned long long family:8, id:48, crc:8;
> } bar;
> 
> void foo(bar *x)
> {
>     print("%012llx\n", x->id);
> }
> 
> 
> $ gcc  testcase.c -c -Wall
> testcase.c: In function 'foo':
> testcase.c:9: warning: format '%012llx' expects type 'long long unsigned int',
>                        but argument 2 has type 'long long unsigned int'

The problem here is the text of the diagnostic, not the fact of the 
diagnostic - the argument type is really "unsigned long long:48" which is 
not promoted to plain unsigned long long, so there is indeed undefined 
behavior on execution.  I.e., pp_c_type_specifier where it does

      if (TYPE_NAME (t))
        t = TYPE_NAME (t);
      else
        t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
      pp_c_type_specifier (pp, t);

should check for the case of integer types with precision smaller than 
that of the mode and display them specially.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21962


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