Re: [Mingw-w64-public] [PATCH 2/2] headers: Don't use the ms_printf/scanf and gnu_printf/scanf format attributes with clang

2024-05-16 Thread Martin Storsjö

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ö 
---
  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


Re: [Mingw-w64-public] [PATCH 2/2] headers: Don't use the ms_printf/scanf and gnu_printf/scanf format attributes with clang

2024-05-16 Thread LIU Hao

在 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ö 
---
  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?


--
Best regards,
LIU Hao



OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH 2/2] headers: Don't use the ms_printf/scanf and gnu_printf/scanf format attributes with clang

2024-05-16 Thread 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ö 
---
 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)))
+
+#define __MINGW_MS_SCANF(__format,__args) \
+  __attribute__((__format__(scanf,  __format,__args)))
+
+#define __MINGW_GNU_PRINTF(__format,__args) \
+  __attribute__((__format__(printf,__format,__args)))
+
+#define __MINGW_GNU_SCANF(__format,__args) \
+  __attribute__((__format__(scanf, __format,__args)))
+#else
 #define __MINGW_MS_PRINTF(__format,__args) \
   __attribute__((__format__(ms_printf, __format,__args)))
 
@@ -278,6 +291,7 @@
 
 #define __MINGW_GNU_SCANF(__format,__args) \
   __attribute__((__format__(gnu_scanf, __format,__args)))
+#endif /* !__clang__ */
 
 #undef __mingw_ovr
 
-- 
2.34.1



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public