[PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89

Liu Hao lh_mouse@126.com
Thu Nov 12 15:12:54 GMT 2020


在 2020/11/12 18:18, Jonathan Yong 写道:
> libgomp build fails because of the false -Wformat error, even though:
> 1. Correct C99 inttypes.h macros are used.
> 2. __mingw_* C99 wrappers are used.
> 3. The printf attribute is used, but it was aliased to ms_printf
> 
> The attached patch makes mingw-w64 printf attribute equivalent to other platforms on C99 or later.
> This allows libgomp to build again with -Werror on. This patch should not affect the original
> mingw.org distribution in any way.
> 

According to the conversation on IRC, I personally consider this inappropriate. Although the `ll`
modifier is specified by C99 for `long long`, there are many more that don't conform to C99 without
UCRT:

1. The `z` modifier for `size_t` is unrecognized.
2. The `t` modifier for `ptrdiff_t` is unrecognized.
3. The `L` modifier for `long double` is accepted but ignored due to
   the fact that MSABI uses an 8-byte type.


> For C99 or later, the mingw-w64 headers already wrap printf/scanf properly, and inttypes.h also
> gives the correct C99 specifiers, so it makes sense to treat the printf attribute as C99 compliant.
> Under C89 mode, the headers would produce MS specific specifiers, so the printf attribute under C89
> reverts to the old behavior of being aliased to ms_printf.
> 
> This might break other code that assumes differently however. I don't think there is a solution to
> satisfy everyone, but at least this allows C99/C++11 compliant code to build again with -Werror.
> Comments?

My humble opinion is that people should have gotten used to the `ll` specifier so I propose a
different patch that enables it unconditionally. As Jonathan Yong pointed out, GCC is impossible to
predict where the target executable will run. It may be reasonable to expect Vista+ instead of an
ancient one. Users who still code for XP- should probably handle such differentiation themselves. In
comparison, MSVC does not have such format checks at all.

I started bootstrapping GCC a few minutes ago. It's not gonna finish very soon so I send this patch
for your comments.



-- 
Best regards,
LH_Mouse
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 9999-gcc-Add-ll-and-L-length-modifiers-for-ms_printf.patch
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20201112/ef5ca507/attachment.ksh>


More information about the Gcc-patches mailing list