Christian Franke wrote:
> ...
>
> The bug is likely in g++ itself. If __USE_MINGW_ANSI_STDIO is not set,
> format checking works, but interestingly the prototype does not provide
> a format attribute in this case:
>
> /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:
> ...
> #if __USE_MINGW_ANSI_STDIO
> ...
> __mingw_ovr
> __attribute__((__format__ (gnu_printf, 1, 2))) ...
> int printf (const char *__format, ...) { ... }
> ...
> #else /* !__USE_MINGW_ANSI_STDIO */
> ...
>     int __cdecl printf(const char * __restrict__ _Format,...);
>     // __attribute__((__format__(ms_printf, 1, 2)))<<--- MISSING!
> ...
> #endif /* __USE_MINGW_ANSI_STDIO */
>
> So there is likely some special handling for printf() done by the compiler.
> (Another: gcc/g++ convert printf("Foo\n") to puts("Foo") regardless of
> -O level).
>
> Overriding the build in format attribute by the new printf() inline
> wrapper in MinGW stdio.h might not work properly.

The __mingw_ovr macro adds the "static" attribute only for C, not for C++.
Interestingly the bogus warning also appears in C if "static" is removed.

Here a testcase which does not depend on stdio.h & friends:

$ cat testfmt2.c
#ifdef __cplusplus
extern "C" {
#endif

#if STATIC
static
#endif
__inline__ __attribute__((format (gnu_printf, 1, 2)))
int printf(const char *__format, ...) { return 0; }

#ifdef __cplusplus
}
#endif

int main()
{
   printf("%lld\n", 42LL);
   return 0;
}

$ i686-w64-mingw32-gcc -Wformat testfmt2.c
testfmt2.c: In function 'main':
testfmt2.c:18:3: warning: unknown conversion type character 'l' in format
testfmt2.c:18:3: warning: too many arguments for format

$ i686-w64-mingw32-gcc -Wformat -DSTATIC testfmt2.c

$ i686-w64-mingw32-gcc -Wformat -fno-builtin testfmt2.c


The static attribute makes no difference in the C++ case:

$ i686-w64-mingw32-g++ -Wformat testfmt2.c
testfmt2.c: In function 'int main()':
testfmt2.c:18:24: warning: unknown conversion type character 'l' in format
testfmt2.c:18:24: warning: too many arguments for format

$ i686-w64-mingw32-g++ -Wformat -DSTATIC testfmt2.c
testfmt2.c: In function 'int main()':
testfmt2.c:18:24: warning: unknown conversion type character 'l' in format
testfmt2.c:18:24: warning: too many arguments for format

$ i686-w64-mingw32-g++ -Wformat -fno-builtin testfmt2.c

Christian


------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to