This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/21962] 4.0/4.1 Regression] ] format '%012llx' expects type X, but argument has type X
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jun 2005 16:32:43 -0000
- Subject: [Bug c/21962] 4.0/4.1 Regression] ] format '%012llx' expects type X, but argument has type X
- References: <20050608145507.21962.pluto@agmk.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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