On Thu, 16 May 2024, LIU Hao wrote:
在 2024-05-16 17:05, Martin Storsjö 写道:
Clang doesn't support the ms_printf/scanf and gnu_printf/scanf
format attributes, only plain "printf" and "scanf".
We already expand e.g. __MINGW_PRINTF_FORMAT (which differs depending
on __USE_MINGW_ANSI_STDIO) into plain "printf" for Clang, since
015e637b4b24d9915162ab877ed539ad0e657951. However, a number
of functions explicitly declared either gnu or ms style formats,
which caused these functions to not get any format string diagnostics.
This fixes https://github.com/llvm/llvm-project/issues/68995,
which reported that no warnings are produced for mismatched
printf/scanf format strings, when compiling with Clang, with
a toolchain targeting msvcrt (i.e. in practice using
__USE_MINGW_ANSI_STDIO enabled).
Signed-off-by: Martin Storsjö <mar...@martin.st>
---
mingw-w64-headers/crt/_mingw_mac.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/mingw-w64-headers/crt/_mingw_mac.h
b/mingw-w64-headers/crt/_mingw_mac.h
index 9de143e5d..6c133d00e 100644
--- a/mingw-w64-headers/crt/_mingw_mac.h
+++ b/mingw-w64-headers/crt/_mingw_mac.h
@@ -267,6 +267,19 @@
# define __MINGW_ATTRIB_DEPRECATED_SEC_WARN
#endif
+#ifdef __clang__
+#define __MINGW_MS_PRINTF(__format,__args) \
+ __attribute__((__format__(printf, __format,__args)))
While this idea is reasonable; I would like to suggest changing
__attribute__((__format__(printf, __format,__args)))
to
__attribute__((__format__(__printf__, __format, __args)))
i.e. reserved names are to be used within standard headers. What do you
think?
Thanks, that's probably a good idea.
I guess we should do the same change for gnu/ms_printf/scanf too, and for
__MINGW_PRINTF_FORMAT, in a separate change.
// Martin
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public