This is the mail archive of the cygwin mailing list for the Cygwin 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]

Re: mingw64-i686-gcc-4.5.3-4: -Wformat warnings broken in C++


On 1/5/2012 02:31, Christian Franke wrote:
> When printf/scanf functions from MinGW runtime are selected via
> __USE_MINGW_ANSI_STDIO, then format string checking is broken. This only
> affects the C++ compiler:
> 
> 
> $ cygcheck -f /usr/bin/i686-w64-mingw32-g++
> mingw64-i686-gcc-g++-4.5.3-4
> 
> $ cat testfmt.c
> #define __USE_MINGW_ANSI_STDIO 1
> #include <stdio.h>
> 
> void myprintf(const char *, ...)
>   __attribute__((format(gnu_printf,1,2)));
> 
> int main()
> {
>   long long x = 42;
>   printf("%lld\n", x); // C++: Bogus warning
>   myprintf("%lld\n", x); // No warning (OK)
>   printf("%I64d\n", x); // Warning (OK)
>   return 0;
> }
> 
> $ i686-w64-mingw32-gcc -Wformat -c testfmt.c
> testfmt.c: In function 'main':
> testfmt.c:12:3: warning: format '%I64d' expects type 'int', but argument
> 2 has type 'long long int'
> 
> $ i686-w64-mingw32-g++ -Wformat -c testfmt.c
> testfmt.c: In function 'int main()':
> testfmt.c:10:21: warning: unknown conversion type character 'l' in format
> testfmt.c:10:21: warning: too many arguments for format
> testfmt.c:12:22: warning: format '%I64d' expects type 'int', but
> argument 2 has type 'long long int'
> 
> 
> Interestingly the bogus warning only occurs for standard functions like
> printf(). These are replaced by inline functions in MinGW stdio.h if
> __USE_MINGW_ANSI_STDIO is set. Probably a subtle bug in the handling of
> functions known by the compiler.
> 
> 
> Another observation: Include files from C++ standard library (e.g.
> <string>) now silently set __USE_MINGW_ANSI_STDIO:
> 
> /usr/lib/gcc/i686-w64-mingw32/4.5.3/include/c++/i686-w64-mingw32/bits/os_defines.h:
> 
> ...
> #undef __USE_MINGW_ANSI_STDIO
> #define __USE_MINGW_ANSI_STDIO 1
> 
> 
> Both are new issues not seen in previous releases. If desired, I could
> resend this report to mingw-w64 list.
> 
> Christian
> 

Yes, please do that. This is an odd problem indeed, maybe a missing
attribute qualifier.

The os_defines.h is done deliberately though, so std::cout and friends
can print 64bit integers properly.


Attachment: signature.asc
Description: OpenPGP digital signature


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