https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8ba61029e12b780070cbb4aebd1b1e203687292d
commit 8ba61029e12b780070cbb4aebd1b1e203687292d Author: Timo Kreuzer <timo.kreu...@reactos.org> AuthorDate: Fri Oct 11 17:09:28 2024 +0200 Commit: Timo Kreuzer <timo.kreu...@reactos.org> CommitDate: Tue Oct 22 08:17:45 2024 +0300 [CRT] Add C++ const correct overloads --- base/applications/rapps/loaddlg.cpp | 2 +- dll/win32/framedyn/chstring.cpp | 4 +- sdk/include/c++/cwchar | 2 + sdk/include/crt/crtdefs.h | 14 +++-- sdk/include/crt/string.h | 100 ++++++++++++++++++++++++++++++++++++ sdk/include/crt/wchar.h | 52 +++++++++++++++++++ 6 files changed, 167 insertions(+), 7 deletions(-) diff --git a/base/applications/rapps/loaddlg.cpp b/base/applications/rapps/loaddlg.cpp index 3e477dbe0b5..7e926c3399f 100644 --- a/base/applications/rapps/loaddlg.cpp +++ b/base/applications/rapps/loaddlg.cpp @@ -635,7 +635,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) { CPathW Path; - PWSTR p, q; + PCWSTR p, q; HWND hDlg = static_cast<DownloadParam *>(param)->Dialog; HWND Item; diff --git a/dll/win32/framedyn/chstring.cpp b/dll/win32/framedyn/chstring.cpp index 89d1b0ed332..d3b9003c2e3 100644 --- a/dll/win32/framedyn/chstring.cpp +++ b/dll/win32/framedyn/chstring.cpp @@ -1001,10 +1001,10 @@ void CHString::ReleaseBuffer(int nNewLength) */ int CHString::ReverseFind(CHSTRING_WCHAR ch) const { - CHSTRING_WCHAR *Last; + CHSTRING_LPCWSTR Last; // Let's use appropriate helper - Last = reinterpret_cast<CHSTRING_WCHAR*>(wcsrchr(reinterpret_cast<LPCWSTR>(m_pchData), ch)); + Last = reinterpret_cast<CHSTRING_LPCWSTR>(wcsrchr(reinterpret_cast<LPCWSTR>(m_pchData), ch)); // We have to return a position, so compute it if (Last) { diff --git a/sdk/include/c++/cwchar b/sdk/include/c++/cwchar index b677e37867d..29534eacab0 100644 --- a/sdk/include/c++/cwchar +++ b/sdk/include/c++/cwchar @@ -130,6 +130,7 @@ namespace std using ::wcsstr; using ::wmemchr; +#ifndef __CORRECT_ISO_CPP_WCHAR_H_PROTO inline wchar_t* wcschr(wchar_t* __p, wchar_t __c) { return wcschr(const_cast<const wchar_t*>(__p), __c); } @@ -149,4 +150,5 @@ namespace std inline wchar_t* wmemchr(wchar_t* __p, wchar_t __c, size_t __n) { return wmemchr(const_cast<const wchar_t*>(__p), __c, __n); } +#endif // __CORRECT_ISO_CPP_WCHAR_H_PROTO } diff --git a/sdk/include/crt/crtdefs.h b/sdk/include/crt/crtdefs.h index e83ed510c35..be29b637cae 100644 --- a/sdk/include/crt/crtdefs.h +++ b/sdk/include/crt/crtdefs.h @@ -37,6 +37,16 @@ #define NO_OLDNAMES #endif +#if defined(__GNUC__) && !defined(__clang__) + #define _CRT_DISABLE_GCC_WARNINGS \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wbuiltin-declaration-mismatch\"") \ + _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") + #define _CRT_RESTORE_GCC_WARNINGS _Pragma("GCC diagnostic pop") +#else // __GNUC__ + #define _CRT_DISABLE_GCC_WARNINGS + #define _CRT_RESTORE_GCC_WARNINGS +#endif // __GNUC__ /** Properties ***************************************************************/ @@ -132,10 +142,6 @@ #define _AGLOBAL #endif -#ifndef _CONST_RETURN - #define _CONST_RETURN -#endif - #ifndef UNALIGNED #if defined(__ia64__) || defined(__x86_64) || defined(__arm__) || defined(__arm64__) #define UNALIGNED __unaligned diff --git a/sdk/include/crt/string.h b/sdk/include/crt/string.h index e0b2f09d96b..b5e4cd4a775 100644 --- a/sdk/include/crt/string.h +++ b/sdk/include/crt/string.h @@ -8,6 +8,8 @@ #include <corecrt.h> +#define __CORRECT_ISO_CPP_STRING_H_PROTO // For stl + #ifdef __cplusplus extern "C" { #endif @@ -29,6 +31,7 @@ extern "C" { _In_ int _Val, _In_ size_t _MaxCount); +_CRT_DISABLE_GCC_WARNINGS _Must_inspect_result_ _CRTIMP _CONST_RETURN @@ -38,6 +41,19 @@ extern "C" { _In_reads_bytes_opt_(_MaxCount) const void *_Buf, _In_ int _Val, _In_ size_t _MaxCount); +_CRT_RESTORE_GCC_WARNINGS + +#if defined __cplusplus + extern "C++" _Must_inspect_result_ + inline void* __CRTDECL memchr( + _In_reads_bytes_opt_(_MaxCount) void *_Buf, + _In_ int _Val, + _In_ size_t _MaxCount) + { + const void *_Bufc = _Buf; + return const_cast<void*>(memchr(_Bufc, _Val, _MaxCount)); + } +#endif _Must_inspect_result_ _CRTIMP @@ -174,6 +190,7 @@ extern "C" { _strdup( _In_opt_z_ const char *_Src); +_CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN @@ -182,6 +199,16 @@ extern "C" { strchr( _In_z_ const char *_Str, _In_ int _Val); +_CRT_RESTORE_GCC_WARNINGS + +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline char* __CRTDECL strchr(_In_z_ char *_String, _In_ int _Ch) + { + return const_cast<char*>(strchr(static_cast<const char*>(_String), _Ch)); + } +#endif // __cplusplus _Check_return_ _CRTIMP @@ -365,6 +392,7 @@ extern "C" { int _Val, size_t _MaxCount); +_CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN @@ -373,7 +401,18 @@ extern "C" { strpbrk( _In_z_ const char *_Str, _In_z_ const char *_Control); +_CRT_RESTORE_GCC_WARNINGS +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline char* __CRTDECL strpbrk(_In_z_ char *_String, _In_z_ const char *_Control) + { + return const_cast<char*>(strpbrk(static_cast<const char*>(_String), _Control)); + } +#endif // __cplusplus + +_CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN @@ -382,6 +421,16 @@ extern "C" { strrchr( _In_z_ const char *_Str, _In_ int _Ch); +_CRT_RESTORE_GCC_WARNINGS + +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline char* __CRTDECL strrchr(_In_z_ char *_String, _In_ int _Ch) + { + return const_cast<char*>(strrchr(static_cast<const char*>(_String), _Ch)); + } +#endif // __cplusplus _CRTIMP char* @@ -397,6 +446,7 @@ extern "C" { _In_z_ const char *_Str, _In_z_ const char *_Control); +_CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN @@ -405,6 +455,16 @@ extern "C" { strstr( _In_z_ const char *_Str, _In_z_ const char *_SubStr); +_CRT_RESTORE_GCC_WARNINGS + +#ifdef __cplusplus + extern "C++" + _Check_return_ _Ret_maybenull_ + inline char* __CRTDECL strstr(_In_z_ char *_String, _In_z_ const char *_SubString) + { + return const_cast<char*>(strstr(static_cast<const char*>(_String), _SubString)); + } +#endif // __cplusplus _Check_return_ _CRTIMP @@ -636,6 +696,16 @@ extern "C" { _In_z_ const wchar_t *_Str, wchar_t _Ch); +#ifdef __cplusplus + extern "C++" + _Check_return_ + _When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1)) + inline wchar_t* __CRTDECL wcschr(_In_z_ wchar_t *_String, wchar_t _C) + { + return const_cast<wchar_t*>(wcschr(static_cast<const wchar_t*>(_String), _C)); + } +#endif // __cplusplus + _Check_return_ _CRTIMP int @@ -714,6 +784,15 @@ extern "C" { _In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control); +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline wchar_t* __cdecl wcspbrk(_In_z_ wchar_t *_Str, _In_z_ const wchar_t *_Control) + { + return const_cast<wchar_t*>(wcspbrk(static_cast<const wchar_t*>(_Str), _Control)); + } +#endif // __cplusplus + _Check_return_ _CRTIMP _CONST_RETURN @@ -723,6 +802,15 @@ extern "C" { _In_z_ const wchar_t *_Str, _In_ wchar_t _Ch); +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline wchar_t* __CRTDECL wcsrchr(_In_z_ wchar_t *_String, _In_ wchar_t _C) + { + return const_cast<wchar_t*>(wcsrchr(static_cast<const wchar_t*>(_String), _C)); + } +#endif // __cplusplus + _Check_return_ _CRTIMP size_t @@ -731,6 +819,7 @@ extern "C" { _In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control); +_CRT_DISABLE_GCC_WARNINGS _When_(return != 0, _Ret_range_(_Str, _Str + _String_length_(_Str) - 1)) _CRTIMP @@ -740,6 +829,17 @@ extern "C" { wcsstr( _In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr); +_CRT_RESTORE_GCC_WARNINGS + +#ifdef __cplusplus + extern "C++" + _Check_return_ _Ret_maybenull_ + _When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1)) + inline wchar_t* __CRTDECL wcsstr(_In_z_ wchar_t *_String, _In_z_ const wchar_t *_SubStr) + { + return const_cast<wchar_t*>(wcsstr(static_cast<const wchar_t*>(_String), _SubStr)); + } +#endif // __cplusplus _Check_return_ _CRTIMP diff --git a/sdk/include/crt/wchar.h b/sdk/include/crt/wchar.h index 765cfd797f4..c558279ed47 100644 --- a/sdk/include/crt/wchar.h +++ b/sdk/include/crt/wchar.h @@ -11,6 +11,8 @@ #define __need___va_list #include <stdarg.h> +#define __CORRECT_ISO_CPP_WCHAR_H_PROTO // For stl + #pragma pack(push,_CRT_PACKING) #ifdef __cplusplus @@ -1926,6 +1928,16 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ const wchar_t *_Str, wchar_t _Ch); +#ifdef __cplusplus + extern "C++" + _Check_return_ + _When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1)) + inline wchar_t* __cdecl wcschr(_In_z_ wchar_t *_String, wchar_t _C) + { + return const_cast<wchar_t*>(wcschr(static_cast<const wchar_t*>(_String), _C)); + } +#endif // __cplusplus + _Check_return_ int __cdecl @@ -1992,6 +2004,15 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control); +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline wchar_t* __cdecl wcspbrk(_In_z_ wchar_t *_Str, _In_z_ const wchar_t *_Control) + { + return const_cast<wchar_t*>(wcspbrk(static_cast<const wchar_t*>(_Str), _Control)); + } +#endif // __cplusplus + _Check_return_ _CONST_RETURN wchar_t* @@ -2000,6 +2021,15 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ const wchar_t *_Str, _In_ wchar_t _Ch); +#ifdef __cplusplus + extern "C++" + _Check_return_ + inline wchar_t* __cdecl wcsrchr(_In_z_ wchar_t *_Str, _In_ wchar_t _Ch) + { + return const_cast<wchar_t*>(wcsrchr(static_cast<const wchar_t*>(_Str), _Ch)); + } +#endif // __cplusplus + _Check_return_ size_t __cdecl @@ -2014,6 +2044,16 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr); +#ifdef __cplusplus + extern "C++" + _Check_return_ _Ret_maybenull_ + _When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1)) + inline wchar_t* __cdecl wcsstr(_In_z_ wchar_t *_String, _In_z_ const wchar_t *_SubStr) + { + return const_cast<wchar_t*>(wcsstr(static_cast<const wchar_t*>(_String), _SubStr)); + } +#endif // __cplusplus + _Check_return_ wchar_t* __cdecl @@ -2467,6 +2507,18 @@ __CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime64(_T _In_ wchar_t _C, _In_ size_t _N); +#ifdef __cplusplus + extern "C++" + inline wchar_t* __cdecl wmemchr( + _In_reads_(_N) wchar_t *_S, + _In_ wchar_t _C, + _In_ size_t _N) + { + const wchar_t *_SC = _S; + return const_cast<wchar_t*>(wmemchr(_SC, _C, _N)); + } +#endif // __cplusplus + int __cdecl wmemcmp(