2012/1/5 Christian Franke <[email protected]>: > [Originally sent to Cygwin mailing list] > > 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.
Issue is fixed on trunk. Version 2 branch still has those issues, as fixes to stdio.h and wchar.h were not merged back. > Downgrading to previous version fixes the problem: > > $ cygcheck -f /usr/bin/i686-w64-mingw32-g++ > mingw64-i686-gcc-g++-4.5.3-3 > > $ i686-w64-mingw32-g++ -Wformat -c testfmt.c > testfmt.c: In function 'int main()': > testfmt.c:12:22: warning: format '%I64d' expects type 'int', but > argument 2 has type 'long long int' > > > 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 > > Is this done to ensure that iostream templates use the correct > FILE/stdio version? > (This was also not present in previous version 4.5.3-3). Yes, this fixes internal libstdc++ usage of printf/scanf routines. libstdc++ internally assumes that printf/scanf function have POSIX semantics. So it makes no sense to make our POSIX printf/scanf functions optional, and so I turned them on by default. To get still MS printf routines in C++, it is recommented to use underscored-function-name instead. > > Christian Regards, Kai ------------------------------------------------------------------------------ Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
