Bug 35649 - Incorrect printf warning: expect double has float
Summary: Incorrect printf warning: expect double has float
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P3 trivial
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 46372 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-20 12:11 UTC by Trevor Morgan
Modified: 2013-08-26 17:12 UTC (History)
5 users (show)

See Also:
Host:
Target: h8300-elf, rx-elf, avr
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-09-23 07:54:25


Attachments
possible fix (479 bytes, patch)
2010-09-22 20:22 UTC, DJ Delorie
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Trevor Morgan 2008-03-20 12:11:47 UTC
With the -Wformat option The code

void foo( float a )
{
    printf("%f",a);
}

give the warning:
foo.c:3: warning: format '%f' expects type 'double', but argument 2 has type 'float'

I believe this is unnecessary because float is promoted to double in variadic functions.
Comment 1 Richard Biener 2008-03-20 12:40:58 UTC
Works for me.  Which target?  Obviously you may need a prototype of printf
available for -Wformat to work at all.
Comment 2 Trevor Morgan 2008-03-20 16:04:34 UTC
Target is h8300-elf running on pc-windows or pc-cygwin

printf prototype:
extern int printf( const char * fmt, ...);
Comment 3 Jim Wilson 2008-03-22 02:13:37 UTC
Subject: Re:   New: Incorrect printf warning: expect double has
 float

6yxwfq202 at sneakemail dot com wrote:
> foo.c:3: warning: format '%f' expects type 'double', but argument 2 has type
> 'float'
> I believe this is unnecessary because float is promoted to double in variadic
> functions.

Small 8/16 bit microprocessors often don't support all FP types. 
h8300.h has for instance
#define FLOAT_TYPE_SIZE 32
#define DOUBLE_TYPE_SIZE        32
So floats and doubles are the same thing, which is probably confusing 
something in the C front end.  Maybe a type conversion got optimized 
away (folded?) because it was a no-op for instance.  I haven't tried to 
reproduce this.

Jim
Comment 4 DJ Delorie 2010-01-08 20:51:02 UTC
Still present in 4.5 trunk, also fails for rx-elf-gcc with -m32bit-doubles but not with -m64bit-doubles.
Comment 5 DJ Delorie 2010-09-22 20:13:19 UTC
Still fails for both h8300-elf and rx-elf, both on 4.5 branch and 4.6 trunk.
Comment 6 DJ Delorie 2010-09-22 20:22:53 UTC
Created attachment 21866 [details]
possible fix

FYI I've been using this to silence the warning in my local tree...
Comment 7 Paolo Carlini 2010-09-22 20:38:00 UTC
I have a deja vu
Comment 8 joseph@codesourcery.com 2010-09-22 22:40:35 UTC
Subject: Re:  Incorrect printf warning: expect double has float

On Wed, 22 Sep 2010, dj at redhat dot com wrote:

> ------- Comment #6 from dj at redhat dot com  2010-09-22 20:22 -------
> Created an attachment (id=21866)
>  --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21866&action=view)
> possible fix
> 
> FYI I've been using this to silence the warning in my local tree...

That's the wrong fix; instead, change convert_arguments to do the 
conversion from float to double even if they have the same precision.

Comment 9 Manuel López-Ibáñez 2010-09-23 07:54:25 UTC
Why is this waiting? It only requires a fix.
Comment 10 Andrew Pinski 2010-11-08 15:39:05 UTC
*** Bug 46372 has been marked as a duplicate of this bug. ***
Comment 11 Søren Holm 2011-10-15 21:48:25 UTC
Iøm having the same isssue whne compiling with -fshort-double
Comment 12 Trevor Morgan 2013-04-17 15:22:48 UTC
printf( "%f", 2.0D );
will also produce the erroneous warning (tried on rx-elf)