Mail Archives: cygwin/2012/01/04/17:40:48
--------------enig3128FB10175BF4AEE14F64BA
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
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:
>=20
>=20
> $ cygcheck -f /usr/bin/i686-w64-mingw32-g++
> mingw64-i686-gcc-g++-4.5.3-4
>=20
> $ cat testfmt.c
> #define __USE_MINGW_ANSI_STDIO 1
> #include <stdio.h>
>=20
> void myprintf(const char *, ...)
> __attribute__((format(gnu_printf,1,2)));
>=20
> int main()
> {
> long long x =3D 42;
> printf("%lld\n", x); // C++: Bogus warning
> myprintf("%lld\n", x); // No warning (OK)
> printf("%I64d\n", x); // Warning (OK)
> return 0;
> }
>=20
> $ 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'
>=20
> $ 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'
>=20
>=20
> 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.
>=20
>=20
> Another observation: Include files from C++ standard library (e.g.
> <string>) now silently set __USE_MINGW_ANSI_STDIO:
>=20
> /usr/lib/gcc/i686-w64-mingw32/4.5.3/include/c++/i686-w64-mingw32/bits/os_=
defines.h:
>=20
> ...
> #undef __USE_MINGW_ANSI_STDIO
> #define __USE_MINGW_ANSI_STDIO 1
>=20
>=20
> Both are new issues not seen in previous releases. If desired, I could
> resend this report to mingw-w64 list.
>=20
> Christian
>=20
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.
--------------enig3128FB10175BF4AEE14F64BA
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
iEYEARECAAYFAk8E1VIACgkQp56AKe10wHfi3wCeMEMd9A1UZwJVoHFwWwQ932/0
K1UAnj2vFDN7zzaScNqgsqqm9XniISBX
=LdEi
-----END PGP SIGNATURE-----
--------------enig3128FB10175BF4AEE14F64BA--
- Raw text -