Consider the following program, reduced from Lensfun: #include <cstring> extern char *f(const char *first_element, ...) __attribute__((__sentinel__)); static auto N = f("a", "b", NULL); static auto n = f("a", "b", nullptr); static auto z = f("a", "b", 0); #define NULL 123 in C++11 and later, NULL=nullptr so N/n are valid, and z is wrong.
But this is not what we observe: >g++ -c a.cpp -Wall -Wextra -std=c++14 a.cpp:6:9: warning: 'NULL' redefined 6 | #define NULL 123 | ^~~~ In file included from V:/msys2/mingw64/include/c++/15.1.0/cstring:48, from a.cpp:1: V:/msys2/mingw64/include/string.h:34:9: note: this is the location of the previous definition 34 | #define NULL 0LL | ^~~~ a.cpp:3:18: warning: missing sentinel in function call [-Wformat=] 3 | static auto N = f("a", "b", NULL); | ~^~~~~~~~~~~~~~~~ a.cpp:5:18: warning: missing sentinel in function call [-Wformat=] 5 | static auto z = f("a", "b", 0); | ~^~~~~~~~~~~~~ (Clang agrees here and in the other sample). "Real" libstdc++/string.h/&c. as part of the GCC distribution uses #define NULL __null and so does our stddef.h. This is the correct implementation. But other headers define NULL=0/0LL, which is not only wrong, but also changes program behaviour based on inclusion order! patch -p3ing this patch into my MSYS2 installation I observe >g++ -c a.cpp -Wall -Wextra -std=c++14 a.cpp:6:9: warning: 'NULL' redefined 6 | #define NULL 123 | ^~~~ In file included from V:/msys2/mingw64/include/c++/15.1.0/cstring:48, from a.cpp:1: V:/msys2/mingw64/include/string.h:31:9: note: this is the location of the previous definition 31 | #define NULL __null | ^~~~ a.cpp:5:18: warning: missing sentinel in function call [-Wformat=] 5 | static auto z = f("a", "b", 0); | ~^~~~~~~~~~~~~ which is correct. --- Please keep me in CC, as I'm not subscribed. mingw-w64-crt/include/oscalls.h | 4 +++- mingw-w64-headers/crt/crtdbg.h | 4 +++- mingw-w64-headers/crt/locale.h | 4 +++- mingw-w64-headers/crt/setjmp.h | 4 +++- mingw-w64-headers/crt/stdio.h | 4 +++- mingw-w64-headers/crt/stdlib.h | 4 +++- mingw-w64-headers/crt/string.h | 4 +++- mingw-w64-headers/crt/tchar.h | 4 +++- mingw-w64-headers/crt/time.h | 4 +++- mingw-w64-headers/crt/wchar.h | 4 +++- mingw-w64-headers/include/fci.h | 10 ++++++++++ mingw-w64-headers/include/fdi.h | 10 ++++++++++ mingw-w64-headers/include/lmcons.h | 4 +++- mingw-w64-headers/include/minwindef.h | 4 +++- mingw-w64-headers/include/ntdef.h | 10 ++++++---- mingw-w64-tools/widl/include/minwindef.h | 4 +++- 16 files changed, 65 insertions(+), 17 deletions(-) diff --git a/mingw-w64-crt/include/oscalls.h b/mingw-w64-crt/include/oscalls.h index 670a6f748..887aa4a1f 100644 --- a/mingw-w64-crt/include/oscalls.h +++ b/mingw-w64-crt/include/oscalls.h @@ -23,7 +23,9 @@ #include <windows.h> #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #define NULL 0 #else #define NULL ((void *)0) diff --git a/mingw-w64-headers/crt/crtdbg.h b/mingw-w64-headers/crt/crtdbg.h index 37014c4fb..d43691547 100644 --- a/mingw-w64-headers/crt/crtdbg.h +++ b/mingw-w64-headers/crt/crtdbg.h @@ -12,7 +12,9 @@ #pragma pack(push,_CRT_PACKING) #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/locale.h b/mingw-w64-headers/crt/locale.h index f69bd6ed7..4a9ac7ac4 100644 --- a/mingw-w64-headers/crt/locale.h +++ b/mingw-w64-headers/crt/locale.h @@ -19,7 +19,9 @@ extern "C" { #endif #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/setjmp.h b/mingw-w64-headers/crt/setjmp.h index 74e7c7ea4..32083729b 100644 --- a/mingw-w64-headers/crt/setjmp.h +++ b/mingw-w64-headers/crt/setjmp.h @@ -11,7 +11,9 @@ #pragma pack(push,_CRT_PACKING) #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h index 91d617fc0..2acf8ee61 100644 --- a/mingw-w64-headers/crt/stdio.h +++ b/mingw-w64-headers/crt/stdio.h @@ -85,7 +85,9 @@ extern "C" { #endif #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h index 482971357..6796e43a0 100644 --- a/mingw-w64-headers/crt/stdlib.h +++ b/mingw-w64-headers/crt/stdlib.h @@ -30,7 +30,9 @@ extern "C" { #endif #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/string.h b/mingw-w64-headers/crt/string.h index 1832e38ed..67c1ea45a 100644 --- a/mingw-w64-headers/crt/string.h +++ b/mingw-w64-headers/crt/string.h @@ -27,7 +27,9 @@ extern "C" { #endif #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/tchar.h b/mingw-w64-headers/crt/tchar.h index 356d8ee52..0bb7a33fe 100644 --- a/mingw-w64-headers/crt/tchar.h +++ b/mingw-w64-headers/crt/tchar.h @@ -1152,7 +1152,9 @@ extern "C" { #define _istlegal(_c) (1) #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h index 2a475eeff..296a4713f 100644 --- a/mingw-w64-headers/crt/time.h +++ b/mingw-w64-headers/crt/time.h @@ -84,7 +84,9 @@ extern "C" { #endif #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h index 0ce7593cf..d6cee70cc 100644 --- a/mingw-w64-headers/crt/wchar.h +++ b/mingw-w64-headers/crt/wchar.h @@ -132,7 +132,9 @@ _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index); #endif #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/include/fci.h b/mingw-w64-headers/include/fci.h index 42eef997e..4853cbe79 100644 --- a/mingw-w64-headers/include/fci.h +++ b/mingw-w64-headers/include/fci.h @@ -56,7 +56,17 @@ extern "C" { #endif #ifndef NULL +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) +#ifndef _WIN64 #define NULL 0 +#else +#define NULL 0LL +#endif /* W64 */ +#else +#define NULL ((void *)0) +#endif #endif typedef struct { diff --git a/mingw-w64-headers/include/fdi.h b/mingw-w64-headers/include/fdi.h index ec594658c..e3c4759ef 100644 --- a/mingw-w64-headers/include/fdi.h +++ b/mingw-w64-headers/include/fdi.h @@ -57,7 +57,17 @@ extern "C" { #endif #ifndef NULL +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) +#ifndef _WIN64 #define NULL 0 +#else +#define NULL 0LL +#endif /* W64 */ +#else +#define NULL ((void *)0) +#endif #endif typedef struct { diff --git a/mingw-w64-headers/include/lmcons.h b/mingw-w64-headers/include/lmcons.h index 1be8b7221..3a6ebbfbd 100644 --- a/mingw-w64-headers/include/lmcons.h +++ b/mingw-w64-headers/include/lmcons.h @@ -99,7 +99,9 @@ #define BACKUP_MSG_FILENAME TEXT("BAK.MSG") #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/include/minwindef.h b/mingw-w64-headers/include/minwindef.h index bf0db9baa..01db5e5f5 100644 --- a/mingw-w64-headers/include/minwindef.h +++ b/mingw-w64-headers/include/minwindef.h @@ -33,7 +33,9 @@ extern "C" { #define MAX_PATH 260 #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else diff --git a/mingw-w64-headers/include/ntdef.h b/mingw-w64-headers/include/ntdef.h index e84702436..6a3cbeaa3 100644 --- a/mingw-w64-headers/include/ntdef.h +++ b/mingw-w64-headers/include/ntdef.h @@ -97,7 +97,9 @@ /* NULL/NULL64 */ #ifndef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else @@ -545,8 +547,8 @@ typedef struct _STRING32 { USHORT Length; USHORT MaximumLength; ULONG Buffer; -} STRING32, *PSTRING32, - UNICODE_STRING32, *PUNICODE_STRING32, +} STRING32, *PSTRING32, + UNICODE_STRING32, *PUNICODE_STRING32, ANSI_STRING32, *PANSI_STRING32; typedef struct _STRING64 { @@ -554,7 +556,7 @@ typedef struct _STRING64 { USHORT MaximumLength; ULONGLONG Buffer; } STRING64, *PSTRING64, - UNICODE_STRING64, *PUNICODE_STRING64, + UNICODE_STRING64, *PUNICODE_STRING64, ANSI_STRING64, *PANSI_STRING64; /* LangID and NLS */ diff --git a/mingw-w64-tools/widl/include/minwindef.h b/mingw-w64-tools/widl/include/minwindef.h index 17da5d9be..ffa4be628 100644 --- a/mingw-w64-tools/widl/include/minwindef.h +++ b/mingw-w64-tools/widl/include/minwindef.h @@ -170,7 +170,9 @@ extern "C" { /* Misc. constants. */ #undef NULL -#ifdef __cplusplus +#if defined(__GNUG__) && __GNUG__ >= 3 +#define NULL __null +#elif defined(__cplusplus) #ifndef _WIN64 #define NULL 0 #else -- 2.39.5
signature.asc
Description: PGP signature
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public