Skip to content

Commit 8ba6102

Browse files
committed
[CRT] Add C++ const correct overloads
1 parent 8c2b8c8 commit 8ba6102

File tree

6 files changed

+167
-7
lines changed

6 files changed

+167
-7
lines changed

base/applications/rapps/loaddlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ unsigned int WINAPI
635635
CDownloadManager::ThreadFunc(LPVOID param)
636636
{
637637
CPathW Path;
638-
PWSTR p, q;
638+
PCWSTR p, q;
639639

640640
HWND hDlg = static_cast<DownloadParam *>(param)->Dialog;
641641
HWND Item;

dll/win32/framedyn/chstring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,10 @@ void CHString::ReleaseBuffer(int nNewLength)
10011001
*/
10021002
int CHString::ReverseFind(CHSTRING_WCHAR ch) const
10031003
{
1004-
CHSTRING_WCHAR *Last;
1004+
CHSTRING_LPCWSTR Last;
10051005

10061006
// Let's use appropriate helper
1007-
Last = reinterpret_cast<CHSTRING_WCHAR*>(wcsrchr(reinterpret_cast<LPCWSTR>(m_pchData), ch));
1007+
Last = reinterpret_cast<CHSTRING_LPCWSTR>(wcsrchr(reinterpret_cast<LPCWSTR>(m_pchData), ch));
10081008
// We have to return a position, so compute it
10091009
if (Last)
10101010
{

sdk/include/c++/cwchar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ namespace std
130130
using ::wcsstr;
131131
using ::wmemchr;
132132

133+
#ifndef __CORRECT_ISO_CPP_WCHAR_H_PROTO
133134
inline wchar_t*
134135
wcschr(wchar_t* __p, wchar_t __c)
135136
{ return wcschr(const_cast<const wchar_t*>(__p), __c); }
@@ -149,4 +150,5 @@ namespace std
149150
inline wchar_t*
150151
wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
151152
{ return wmemchr(const_cast<const wchar_t*>(__p), __c, __n); }
153+
#endif // __CORRECT_ISO_CPP_WCHAR_H_PROTO
152154
}

sdk/include/crt/crtdefs.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
#define NO_OLDNAMES
3838
#endif
3939

40+
#if defined(__GNUC__) && !defined(__clang__)
41+
#define _CRT_DISABLE_GCC_WARNINGS \
42+
_Pragma("GCC diagnostic push") \
43+
_Pragma("GCC diagnostic ignored \"-Wbuiltin-declaration-mismatch\"") \
44+
_Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
45+
#define _CRT_RESTORE_GCC_WARNINGS _Pragma("GCC diagnostic pop")
46+
#else // __GNUC__
47+
#define _CRT_DISABLE_GCC_WARNINGS
48+
#define _CRT_RESTORE_GCC_WARNINGS
49+
#endif // __GNUC__
4050

4151
/** Properties ***************************************************************/
4252

@@ -132,10 +142,6 @@
132142
#define _AGLOBAL
133143
#endif
134144

135-
#ifndef _CONST_RETURN
136-
#define _CONST_RETURN
137-
#endif
138-
139145
#ifndef UNALIGNED
140146
#if defined(__ia64__) || defined(__x86_64) || defined(__arm__) || defined(__arm64__)
141147
#define UNALIGNED __unaligned

sdk/include/crt/string.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <corecrt.h>
1010

11+
#define __CORRECT_ISO_CPP_STRING_H_PROTO // For stl
12+
1113
#ifdef __cplusplus
1214
extern "C" {
1315
#endif
@@ -29,6 +31,7 @@ extern "C" {
2931
_In_ int _Val,
3032
_In_ size_t _MaxCount);
3133

34+
_CRT_DISABLE_GCC_WARNINGS
3235
_Must_inspect_result_
3336
_CRTIMP
3437
_CONST_RETURN
@@ -38,6 +41,19 @@ extern "C" {
3841
_In_reads_bytes_opt_(_MaxCount) const void *_Buf,
3942
_In_ int _Val,
4043
_In_ size_t _MaxCount);
44+
_CRT_RESTORE_GCC_WARNINGS
45+
46+
#if defined __cplusplus
47+
extern "C++" _Must_inspect_result_
48+
inline void* __CRTDECL memchr(
49+
_In_reads_bytes_opt_(_MaxCount) void *_Buf,
50+
_In_ int _Val,
51+
_In_ size_t _MaxCount)
52+
{
53+
const void *_Bufc = _Buf;
54+
return const_cast<void*>(memchr(_Bufc, _Val, _MaxCount));
55+
}
56+
#endif
4157

4258
_Must_inspect_result_
4359
_CRTIMP
@@ -174,6 +190,7 @@ extern "C" {
174190
_strdup(
175191
_In_opt_z_ const char *_Src);
176192

193+
_CRT_DISABLE_GCC_WARNINGS
177194
_Check_return_
178195
_CRTIMP
179196
_CONST_RETURN
@@ -182,6 +199,16 @@ extern "C" {
182199
strchr(
183200
_In_z_ const char *_Str,
184201
_In_ int _Val);
202+
_CRT_RESTORE_GCC_WARNINGS
203+
204+
#ifdef __cplusplus
205+
extern "C++"
206+
_Check_return_
207+
inline char* __CRTDECL strchr(_In_z_ char *_String, _In_ int _Ch)
208+
{
209+
return const_cast<char*>(strchr(static_cast<const char*>(_String), _Ch));
210+
}
211+
#endif // __cplusplus
185212

186213
_Check_return_
187214
_CRTIMP
@@ -365,6 +392,7 @@ extern "C" {
365392
int _Val,
366393
size_t _MaxCount);
367394

395+
_CRT_DISABLE_GCC_WARNINGS
368396
_Check_return_
369397
_CRTIMP
370398
_CONST_RETURN
@@ -373,7 +401,18 @@ extern "C" {
373401
strpbrk(
374402
_In_z_ const char *_Str,
375403
_In_z_ const char *_Control);
404+
_CRT_RESTORE_GCC_WARNINGS
376405

406+
#ifdef __cplusplus
407+
extern "C++"
408+
_Check_return_
409+
inline char* __CRTDECL strpbrk(_In_z_ char *_String, _In_z_ const char *_Control)
410+
{
411+
return const_cast<char*>(strpbrk(static_cast<const char*>(_String), _Control));
412+
}
413+
#endif // __cplusplus
414+
415+
_CRT_DISABLE_GCC_WARNINGS
377416
_Check_return_
378417
_CRTIMP
379418
_CONST_RETURN
@@ -382,6 +421,16 @@ extern "C" {
382421
strrchr(
383422
_In_z_ const char *_Str,
384423
_In_ int _Ch);
424+
_CRT_RESTORE_GCC_WARNINGS
425+
426+
#ifdef __cplusplus
427+
extern "C++"
428+
_Check_return_
429+
inline char* __CRTDECL strrchr(_In_z_ char *_String, _In_ int _Ch)
430+
{
431+
return const_cast<char*>(strrchr(static_cast<const char*>(_String), _Ch));
432+
}
433+
#endif // __cplusplus
385434

386435
_CRTIMP
387436
char*
@@ -397,6 +446,7 @@ extern "C" {
397446
_In_z_ const char *_Str,
398447
_In_z_ const char *_Control);
399448

449+
_CRT_DISABLE_GCC_WARNINGS
400450
_Check_return_
401451
_CRTIMP
402452
_CONST_RETURN
@@ -405,6 +455,16 @@ extern "C" {
405455
strstr(
406456
_In_z_ const char *_Str,
407457
_In_z_ const char *_SubStr);
458+
_CRT_RESTORE_GCC_WARNINGS
459+
460+
#ifdef __cplusplus
461+
extern "C++"
462+
_Check_return_ _Ret_maybenull_
463+
inline char* __CRTDECL strstr(_In_z_ char *_String, _In_z_ const char *_SubString)
464+
{
465+
return const_cast<char*>(strstr(static_cast<const char*>(_String), _SubString));
466+
}
467+
#endif // __cplusplus
408468

409469
_Check_return_
410470
_CRTIMP
@@ -636,6 +696,16 @@ extern "C" {
636696
_In_z_ const wchar_t *_Str,
637697
wchar_t _Ch);
638698

699+
#ifdef __cplusplus
700+
extern "C++"
701+
_Check_return_
702+
_When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1))
703+
inline wchar_t* __CRTDECL wcschr(_In_z_ wchar_t *_String, wchar_t _C)
704+
{
705+
return const_cast<wchar_t*>(wcschr(static_cast<const wchar_t*>(_String), _C));
706+
}
707+
#endif // __cplusplus
708+
639709
_Check_return_
640710
_CRTIMP
641711
int
@@ -714,6 +784,15 @@ extern "C" {
714784
_In_z_ const wchar_t *_Str,
715785
_In_z_ const wchar_t *_Control);
716786

787+
#ifdef __cplusplus
788+
extern "C++"
789+
_Check_return_
790+
inline wchar_t* __cdecl wcspbrk(_In_z_ wchar_t *_Str, _In_z_ const wchar_t *_Control)
791+
{
792+
return const_cast<wchar_t*>(wcspbrk(static_cast<const wchar_t*>(_Str), _Control));
793+
}
794+
#endif // __cplusplus
795+
717796
_Check_return_
718797
_CRTIMP
719798
_CONST_RETURN
@@ -723,6 +802,15 @@ extern "C" {
723802
_In_z_ const wchar_t *_Str,
724803
_In_ wchar_t _Ch);
725804

805+
#ifdef __cplusplus
806+
extern "C++"
807+
_Check_return_
808+
inline wchar_t* __CRTDECL wcsrchr(_In_z_ wchar_t *_String, _In_ wchar_t _C)
809+
{
810+
return const_cast<wchar_t*>(wcsrchr(static_cast<const wchar_t*>(_String), _C));
811+
}
812+
#endif // __cplusplus
813+
726814
_Check_return_
727815
_CRTIMP
728816
size_t
@@ -731,6 +819,7 @@ extern "C" {
731819
_In_z_ const wchar_t *_Str,
732820
_In_z_ const wchar_t *_Control);
733821

822+
_CRT_DISABLE_GCC_WARNINGS
734823
_When_(return != 0,
735824
_Ret_range_(_Str, _Str + _String_length_(_Str) - 1))
736825
_CRTIMP
@@ -740,6 +829,17 @@ extern "C" {
740829
wcsstr(
741830
_In_z_ const wchar_t *_Str,
742831
_In_z_ const wchar_t *_SubStr);
832+
_CRT_RESTORE_GCC_WARNINGS
833+
834+
#ifdef __cplusplus
835+
extern "C++"
836+
_Check_return_ _Ret_maybenull_
837+
_When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1))
838+
inline wchar_t* __CRTDECL wcsstr(_In_z_ wchar_t *_String, _In_z_ const wchar_t *_SubStr)
839+
{
840+
return const_cast<wchar_t*>(wcsstr(static_cast<const wchar_t*>(_String), _SubStr));
841+
}
842+
#endif // __cplusplus
743843

744844
_Check_return_
745845
_CRTIMP

sdk/include/crt/wchar.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#define __need___va_list
1212
#include <stdarg.h>
1313

14+
#define __CORRECT_ISO_CPP_WCHAR_H_PROTO // For stl
15+
1416
#pragma pack(push,_CRT_PACKING)
1517

1618
#ifdef __cplusplus
@@ -1926,6 +1928,16 @@ _CRTIMP int __cdecl iswblank(wint_t _C);
19261928
_In_z_ const wchar_t *_Str,
19271929
wchar_t _Ch);
19281930

1931+
#ifdef __cplusplus
1932+
extern "C++"
1933+
_Check_return_
1934+
_When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1))
1935+
inline wchar_t* __cdecl wcschr(_In_z_ wchar_t *_String, wchar_t _C)
1936+
{
1937+
return const_cast<wchar_t*>(wcschr(static_cast<const wchar_t*>(_String), _C));
1938+
}
1939+
#endif // __cplusplus
1940+
19291941
_Check_return_
19301942
int
19311943
__cdecl
@@ -1992,6 +2004,15 @@ _CRTIMP int __cdecl iswblank(wint_t _C);
19922004
_In_z_ const wchar_t *_Str,
19932005
_In_z_ const wchar_t *_Control);
19942006

2007+
#ifdef __cplusplus
2008+
extern "C++"
2009+
_Check_return_
2010+
inline wchar_t* __cdecl wcspbrk(_In_z_ wchar_t *_Str, _In_z_ const wchar_t *_Control)
2011+
{
2012+
return const_cast<wchar_t*>(wcspbrk(static_cast<const wchar_t*>(_Str), _Control));
2013+
}
2014+
#endif // __cplusplus
2015+
19952016
_Check_return_
19962017
_CONST_RETURN
19972018
wchar_t*
@@ -2000,6 +2021,15 @@ _CRTIMP int __cdecl iswblank(wint_t _C);
20002021
_In_z_ const wchar_t *_Str,
20012022
_In_ wchar_t _Ch);
20022023

2024+
#ifdef __cplusplus
2025+
extern "C++"
2026+
_Check_return_
2027+
inline wchar_t* __cdecl wcsrchr(_In_z_ wchar_t *_Str, _In_ wchar_t _Ch)
2028+
{
2029+
return const_cast<wchar_t*>(wcsrchr(static_cast<const wchar_t*>(_Str), _Ch));
2030+
}
2031+
#endif // __cplusplus
2032+
20032033
_Check_return_
20042034
size_t
20052035
__cdecl
@@ -2014,6 +2044,16 @@ _CRTIMP int __cdecl iswblank(wint_t _C);
20142044
_In_z_ const wchar_t *_Str,
20152045
_In_z_ const wchar_t *_SubStr);
20162046

2047+
#ifdef __cplusplus
2048+
extern "C++"
2049+
_Check_return_ _Ret_maybenull_
2050+
_When_(return != NULL, _Ret_range_(_String, _String + _String_length_(_String) - 1))
2051+
inline wchar_t* __cdecl wcsstr(_In_z_ wchar_t *_String, _In_z_ const wchar_t *_SubStr)
2052+
{
2053+
return const_cast<wchar_t*>(wcsstr(static_cast<const wchar_t*>(_String), _SubStr));
2054+
}
2055+
#endif // __cplusplus
2056+
20172057
_Check_return_
20182058
wchar_t*
20192059
__cdecl
@@ -2467,6 +2507,18 @@ __CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime64(_T
24672507
_In_ wchar_t _C,
24682508
_In_ size_t _N);
24692509

2510+
#ifdef __cplusplus
2511+
extern "C++"
2512+
inline wchar_t* __cdecl wmemchr(
2513+
_In_reads_(_N) wchar_t *_S,
2514+
_In_ wchar_t _C,
2515+
_In_ size_t _N)
2516+
{
2517+
const wchar_t *_SC = _S;
2518+
return const_cast<wchar_t*>(wmemchr(_SC, _C, _N));
2519+
}
2520+
#endif // __cplusplus
2521+
24702522
int
24712523
__cdecl
24722524
wmemcmp(

0 commit comments

Comments
 (0)