headers: fix _CONST_RETURN warnings With previous changes to _CONST_RETURN, GCC 7-14 will warn about strchr and similar functions with -Wbuiltin-declaration-mismatch, as GCC's builtin versions of these functions return non-const pointers even in C++ mode. Other versions of GCC and all versions of Clang are fine. This commit fixes this by moving all C++ declartions of these functions under extern "C++", similar to what glibc does. The difference between we and glibc is that we only use __asm__ for the const versions of these functions, while glibc uses it for both. This is to avoid -Wodr warnings under LTO. Signed-off-by: Zhongteng Gui <dragon-archer@outlook.com> Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-headers/crt/corecrt_memory.h b/mingw-w64-headers/crt/corecrt_memory.h index 7eb4573..779887d 100644 --- a/mingw-w64-headers/crt/corecrt_memory.h +++ b/mingw-w64-headers/crt/corecrt_memory.h
@@ -14,7 +14,6 @@ #if !defined(__STRICT_ANSI__) || defined(_GNU_SOURCE) || __STDC_VERSION__ + 0 >= 202311L || _XOPEN_SOURCE + 0 >= 600 void * __cdecl memccpy(void *_Dst,const void *_Src,int _Val,size_t _Size); #endif - _CONST_RETURN void *__cdecl memchr(const void *_Buf ,int _Val,size_t _MaxCount); _CRTIMP int __cdecl _memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale); int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size); @@ -34,8 +33,13 @@ _CRT_END_C_HEADER #ifdef __cplusplus -extern "C++" inline void* memchr(void* __s, int __c, size_t __n) -{ return const_cast<void*>(memchr(const_cast<const void*>(__s), __c, __n)); } +extern "C++" { + const void* __cdecl memchr(const void*, int, size_t) __MINGW_ASM_CALL(memchr); + inline void* __cdecl memchr(void* _Buf, int _Val, size_t _MaxCount) + { return const_cast<void*>(memchr(const_cast<const void*>(_Buf), _Val, _MaxCount)); } +} +#else + void* __cdecl memchr(const void* _Buf, int _Val, size_t _MaxCount); #endif #endif
diff --git a/mingw-w64-headers/crt/corecrt_wstring.h b/mingw-w64-headers/crt/corecrt_wstring.h index 22227a7..3231117 100644 --- a/mingw-w64-headers/crt/corecrt_wstring.h +++ b/mingw-w64-headers/crt/corecrt_wstring.h
@@ -26,7 +26,6 @@ #pragma pop_macro("_wcsdup") #endif wchar_t *__cdecl wcscat(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Source) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; - _CONST_RETURN wchar_t *__cdecl wcschr(const wchar_t *_Str,wchar_t _Ch); int __cdecl wcscmp(const wchar_t *_Str1,const wchar_t *_Str2); wchar_t *__cdecl wcscpy(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Source) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; size_t __cdecl wcscspn(const wchar_t *_Str,const wchar_t *_Control); @@ -36,10 +35,7 @@ int __cdecl wcsncmp(const wchar_t *_Str1,const wchar_t *_Str2,size_t _MaxCount); wchar_t *__cdecl wcsncpy(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Source,size_t _Count) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; wchar_t *__cdecl _wcsncpy_l(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Source,size_t _Count,_locale_t _Locale) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; - _CONST_RETURN wchar_t *__cdecl wcspbrk(const wchar_t *_Str,const wchar_t *_Control); - _CONST_RETURN wchar_t *__cdecl wcsrchr(const wchar_t *_Str,wchar_t _Ch); size_t __cdecl wcsspn(const wchar_t *_Str,const wchar_t *_Control); - _CONST_RETURN wchar_t *__cdecl wcsstr(const wchar_t *_Str,const wchar_t *_SubStr); _CRTIMP wchar_t *__cdecl wcstok(wchar_t * __restrict__ _Str,const wchar_t * __restrict__ _Delim,wchar_t ** __restrict__ _Ptr) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; _CRTIMP wchar_t *__cdecl _wcstok(wchar_t * __restrict__ _Str,const wchar_t * __restrict__ _Delim) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; #if defined(_CRT_NON_CONFORMING_WCSTOK) && !defined(__cplusplus) @@ -94,24 +90,29 @@ _CRT_END_C_HEADER -/** - * ISO C++ requires both const and non-const versions of these functions. - * The const versions have been declared above. The non-const versions are declared here. - */ -#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO +#ifdef __cplusplus extern "C++" { - inline wchar_t* wcschr(wchar_t* __p, wchar_t __c) - { return const_cast<wchar_t*>(wcschr(const_cast<const wchar_t*>(__p), __c)); } + const wchar_t* __cdecl wcschr(const wchar_t*, wchar_t) __MINGW_ASM_CALL(wcschr); + inline wchar_t* wcschr(wchar_t* _Str, wchar_t _Ch) + { return const_cast<wchar_t*>(wcschr(const_cast<const wchar_t*>(_Str), _Ch)); } - inline wchar_t* wcspbrk(wchar_t* __s1, const wchar_t* __s2) - { return const_cast<wchar_t*>(wcspbrk(const_cast<const wchar_t*>(__s1), __s2)); } + const wchar_t* __cdecl wcspbrk(const wchar_t*, const wchar_t*) __MINGW_ASM_CALL(wcspbrk); + inline wchar_t* wcspbrk(wchar_t* _Str, const wchar_t* _Control) + { return const_cast<wchar_t*>(wcspbrk(const_cast<const wchar_t*>(_Str), _Control)); } - inline wchar_t* wcsrchr(wchar_t* __p, wchar_t __c) - { return const_cast<wchar_t*>(wcsrchr(const_cast<const wchar_t*>(__p), __c)); } + const wchar_t* __cdecl wcsrchr(const wchar_t*, wchar_t) __MINGW_ASM_CALL(wcsrchr); + inline wchar_t* wcsrchr(wchar_t* _Str, wchar_t _Ch) + { return const_cast<wchar_t*>(wcsrchr(const_cast<const wchar_t*>(_Str), _Ch)); } - inline wchar_t* wcsstr(wchar_t* __s1, const wchar_t* __s2) - { return const_cast<wchar_t*>(wcsstr(const_cast<const wchar_t*>(__s1), __s2)); } + const wchar_t* __cdecl wcsstr(const wchar_t*, const wchar_t*) __MINGW_ASM_CALL(wcsstr); + inline wchar_t* wcsstr(wchar_t* _Str, const wchar_t* _SubStr) + { return const_cast<wchar_t*>(wcsstr(const_cast<const wchar_t*>(_Str), _SubStr)); } } +#else + wchar_t* __cdecl wcschr(const wchar_t* _Str, wchar_t _Ch); + wchar_t* __cdecl wcspbrk(const wchar_t* _Str, const wchar_t* _Control); + wchar_t* __cdecl wcsrchr(const wchar_t* _Str, wchar_t _Ch); + wchar_t* __cdecl wcsstr(const wchar_t* _Str, const wchar_t* _SubStr); #endif #endif
diff --git a/mingw-w64-headers/crt/string.h b/mingw-w64-headers/crt/string.h index 01859e9..86e44df 100644 --- a/mingw-w64-headers/crt/string.h +++ b/mingw-w64-headers/crt/string.h
@@ -60,7 +60,6 @@ #if !defined(__STRICT_ANSI__) || defined(_GNU_SOURCE) || __STDC_VERSION__ + 0 >= 202311L || _POSIX_C_SOURCE + 0 >= 200809L || _XOPEN_SOURCE + 0 >= 700 char *__cdecl strndup(const char *_Src,size_t _MaxCount); #endif - _CONST_RETURN char *__cdecl strchr(const char *_Str,int _Val); _CRTIMP int __cdecl _stricmp(const char *_Str1,const char *_Str2); _CRTIMP int __cdecl _strcmpi(const char *_Str1,const char *_Str2); _CRTIMP int __cdecl _stricmp_l(const char *_Str1,const char *_Str2,_locale_t _Locale); @@ -84,11 +83,8 @@ char *strncpy(char * __restrict__ _Dest,const char * __restrict__ _Source,size_t _Count) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; _CRTIMP char *__cdecl _strnset(char *_Str,int _Val,size_t _MaxCount) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; _CRTIMP char *__cdecl _strnset_l(char *str,int c,size_t count,_locale_t _Locale) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; - _CONST_RETURN char *__cdecl strpbrk(const char *_Str,const char *_Control); - _CONST_RETURN char *__cdecl strrchr(const char *_Str,int _Ch); _CRTIMP char *__cdecl _strrev(char *_Str); size_t __cdecl strspn(const char *_Str,const char *_Control); - _CONST_RETURN char *__cdecl strstr(const char *_Str,const char *_SubStr); _CRTIMP char *__cdecl strtok(char * __restrict__ _Str,const char * __restrict__ _Delim) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; #pragma push_macro("strtok_r") #undef strtok_r @@ -122,20 +118,29 @@ _CRT_END_C_HEADER -#ifdef __CORRECT_ISO_CPP_STRING_H_PROTO +#ifdef __cplusplus extern "C++" { - inline char* strchr(char* __s, int __n) - { return const_cast<char*>(strchr(const_cast<const char*>(__s), __n)); } + const char* __cdecl strchr(const char*, int) __MINGW_ASM_CALL(strchr); + inline char* __cdecl strchr(char* _Str, int _Val) + { return const_cast<char*>(strchr(const_cast<const char*>(_Str), _Val)); } - inline char* strpbrk(char* __s1, const char* __s2) - { return const_cast<char*>(strpbrk(const_cast<const char*>(__s1), __s2)); } + const char* __cdecl strpbrk(const char*, const char*) __MINGW_ASM_CALL(strpbrk); + inline char* __cdecl strpbrk(char* _Str, const char* _Control) + { return const_cast<char*>(strpbrk(const_cast<const char*>(_Str), _Control)); } - inline char* strrchr(char* __s, int __n) - { return const_cast<char*>(strrchr(const_cast<const char*>(__s), __n)); } + const char* __cdecl strrchr(const char*, int) __MINGW_ASM_CALL(strrchr); + inline char* __cdecl strrchr(char* _Str, int _Val) + { return const_cast<char*>(strrchr(const_cast<const char*>(_Str), _Val)); } - inline char* strstr(char* __s1, const char* __s2) - { return const_cast<char*>(strstr(const_cast<const char*>(__s1), __s2)); } + const char* __cdecl strstr(const char*, const char*) __MINGW_ASM_CALL(strstr); + inline char* __cdecl strstr(char* _Str, const char* _SubStr) + { return const_cast<char*>(strstr(const_cast<const char*>(_Str), _SubStr)); } } +#else + char* __cdecl strchr(const char* _Str, int _Val); + char* __cdecl strpbrk(const char* _Str, const char* _Control); + char* __cdecl strrchr(const char* _Str, int _Val); + char* __cdecl strstr(const char* _Str, const char* _SubStr); #endif #include <sec_api/string_s.h>
diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h index 357d06b..705f153 100644 --- a/mingw-w64-headers/crt/wchar.h +++ b/mingw-w64-headers/crt/wchar.h
@@ -183,7 +183,6 @@ #ifndef __NO_ISOCEXT /* these need static lib libmingwex.a */ wchar_t *__cdecl wmemset(wchar_t *s, wchar_t c, size_t n); - _CONST_RETURN wchar_t *__cdecl wmemchr(const wchar_t *s, wchar_t c, size_t n); int __cdecl wmemcmp(const wchar_t *s1, const wchar_t *s2,size_t n); wchar_t *__cdecl wmemcpy(wchar_t * __restrict__ s1,const wchar_t * __restrict__ s2,size_t n) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; wchar_t * __cdecl wmempcpy (wchar_t *_Dst, const wchar_t *_Src, size_t _Size); @@ -192,16 +191,25 @@ __MINGW_EXTENSION long long __cdecl wcstoll(const wchar_t * __restrict__ nptr,wchar_t ** __restrict__ endptr, int base); __MINGW_EXTENSION unsigned long long __cdecl wcstoull(const wchar_t * __restrict__ nptr,wchar_t ** __restrict__ endptr, int base); -#ifdef __CORRECT_ISO_CPP_WCHAR_H_PROTO - extern "C++" inline wchar_t* wmemchr(wchar_t* __p, wchar_t __c, size_t __n) - { return const_cast<wchar_t*>(wmemchr(const_cast<const wchar_t*>(__p), __c, __n)); } +#ifdef __cplusplus + extern "C++" { + const wchar_t* __cdecl wmemchr(const wchar_t*, wchar_t, size_t) __MINGW_ASM_CALL(wmemchr); + inline wchar_t* __cdecl wmemchr(wchar_t* _Buf, wchar_t _Val, size_t _MaxCount) + { return const_cast<wchar_t*>(wmemchr(const_cast<const wchar_t*>(_Buf), _Val, _MaxCount)); } + } +#else + wchar_t* __cdecl wmemchr(const wchar_t* _Buf, wchar_t _Val, size_t _MaxCount); #endif + #endif /* __NO_ISOCEXT */ void *__cdecl memmove(void *_Dst,const void *_Src,size_t _MaxCount); void *__cdecl memcpy(void * __restrict__ _Dst,const void * __restrict__ _Src,size_t _MaxCount) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; #ifndef __CRT__NO_INLINE __CRT_INLINE int __cdecl fwide(FILE *_F,int _M) { (void)_F; return (_M); } +#ifdef __cplusplus + extern "C++" +#endif __CRT_INLINE _CONST_RETURN wchar_t *__cdecl wmemchr(const wchar_t *_S,wchar_t _C,size_t _N) { if (_S) { for ( ; 0 < _N; ++_S, --_N)