From ccad7a6a6ebaa2a293bd5d185eedbbb7fd33472a Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 28 Aug 2021 14:36:08 +0700 Subject: [PATCH 1/9] When wchar_t is a real type, users shouldn't see unsigned short machinery --- stl/inc/fstream | 147 --------------- stl/inc/iosfwd | 4 - stl/inc/xlocale | 472 ------------------------------------------------ stl/inc/xstring | 5 - 4 files changed, 628 deletions(-) diff --git a/stl/inc/fstream b/stl/inc/fstream index 9c3c38f7c3d..090c699bb8c 100644 --- a/stl/inc/fstream +++ b/stl/inc/fstream @@ -63,10 +63,6 @@ _INLINE_VAR constexpr bool _Is_any_path = _Is_any_of_v<_Ty extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int); extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int); -#ifdef _NATIVE_WCHAR_T_DEFINED -extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const unsigned short*, ios_base::openmode, int); -#endif // _NATIVE_WCHAR_T_DEFINED - template bool _Fgetc(_Elem& _Ch, FILE* _File) { // get an element from a C stream return _CSTD fread(&_Ch, sizeof(_Elem), 1, _File) == 1; @@ -94,19 +90,6 @@ inline bool _Fgetc(wchar_t& _Wchar, FILE* _File) { // get a wchar_t element from } } -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) { // get an unsigned short element from a C stream - wint_t _Meta; - if ((_Meta = _CSTD fgetwc(_File)) == WEOF) { - return false; - } else { // got one, convert to unsigned short - _Wchar = static_cast(_Meta); - return true; - } -} -#endif // _NATIVE_WCHAR_T_DEFINED - template bool _Fputc(_Elem _Ch, FILE* _File) { // put an element to a C stream return _CSTD fwrite(&_Ch, 1, sizeof(_Elem), _File) == sizeof(_Elem); @@ -122,13 +105,6 @@ inline bool _Fputc(wchar_t _Wchar, FILE* _File) { // put a wchar_t element to a return _CSTD fputwc(_Wchar, _File) != WEOF; } -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -inline bool _Fputc(unsigned short _Wchar, FILE* _File) { // put an unsigned short element to a C stream - return _CSTD fputwc(_Wchar, _File) != WEOF; -} -#endif // _NATIVE_WCHAR_T_DEFINED - template bool _Ungetc(const _Elem&, FILE*) { // put back an arbitrary element to a C stream (always fail) return false; @@ -154,13 +130,6 @@ inline bool _Ungetc(const wchar_t& _Wchar, FILE* _File) { // put back a wchar_t return _CSTD ungetwc(_Wchar, _File) != WEOF; } -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -inline bool _Ungetc(const unsigned short& _Wchar, FILE* _File) { // put back an unsigned short element to a C stream - return _CSTD ungetwc(_Wchar, _File) != WEOF; -} -#endif // _NATIVE_WCHAR_T_DEFINED - template class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer associated with a C stream public: @@ -353,32 +322,6 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#ifdef _NATIVE_WCHAR_T_DEFINED - basic_filebuf* open( - const unsigned short* _Filename, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Myfile) { - return nullptr; - } - - const auto _File = _Fiopen(_Filename, _Mode, _Prot); - if (!_File) { - return nullptr; // open failed - } - - _Init(_File, _Openfl); - _Initcvt(_STD use_facet<_Cvt>(_Mysb::getloc())); - return this; // open succeeded - } - -#if _HAS_OLD_IOSTREAMS_MEMBERS - basic_filebuf* open(const unsigned short* _Filename, ios_base::open_mode _Mode) { - // in standard as const std::filesystem::path::value_type * - return open(_Filename, static_cast(_Mode)); - } -#endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // _NATIVE_WCHAR_T_DEFINED - basic_filebuf* close() { basic_filebuf* _Ans; if (_Myfile) { // put any homing sequence and close file @@ -843,17 +786,6 @@ public: const _Ty& _Path, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) : basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension -#ifdef _NATIVE_WCHAR_T_DEFINED - explicit basic_ifstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in, - int _Prot = ios_base::_Default_open_prot) - : _Mybase(_STD addressof(_Filebuffer)) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) { - _Myios::setstate(ios_base::failbit); - } - } -#endif // _NATIVE_WCHAR_T_DEFINED - explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension basic_ifstream(basic_ifstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) { @@ -922,25 +854,6 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#ifdef _NATIVE_WCHAR_T_DEFINED - void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in, - int _Prot = ios_base::_Default_open_prot) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) { - _Myios::setstate(ios_base::failbit); - } else { - _Myios::clear(); - } - } - -#if _HAS_OLD_IOSTREAMS_MEMBERS - void open(const unsigned short* _Filename, ios_base::open_mode _Mode) { - // in standard as const std::filesystem::path::value_type * - open(_Filename, static_cast(_Mode)); - } -#endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // _NATIVE_WCHAR_T_DEFINED - __CLR_OR_THIS_CALL ~basic_ifstream() noexcept override {} _NODISCARD _Myfb* rdbuf() const { @@ -1026,17 +939,6 @@ public: const _Ty& _Path, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) : basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension -#ifdef _NATIVE_WCHAR_T_DEFINED - explicit basic_ofstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out, - int _Prot = ios_base::_Default_open_prot) - : _Mybase(_STD addressof(_Filebuffer)) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) { - _Myios::setstate(ios_base::failbit); - } - } -#endif // _NATIVE_WCHAR_T_DEFINED - explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension basic_ofstream(basic_ofstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) { @@ -1105,25 +1007,6 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#ifdef _NATIVE_WCHAR_T_DEFINED - void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out, - int _Prot = ios_base::_Default_open_prot) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) { - _Myios::setstate(ios_base::failbit); - } else { - _Myios::clear(); - } - } - -#if _HAS_OLD_IOSTREAMS_MEMBERS - void open(const unsigned short* _Filename, ios_base::open_mode _Mode) { - // in standard as const std::filesystem::path::value_type * - open(_Filename, static_cast(_Mode)); - } -#endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // _NATIVE_WCHAR_T_DEFINED - __CLR_OR_THIS_CALL ~basic_ofstream() noexcept override {} _NODISCARD _Myfb* rdbuf() const { @@ -1214,17 +1097,6 @@ public: int _Prot = ios_base::_Default_open_prot) : basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension -#ifdef _NATIVE_WCHAR_T_DEFINED - explicit basic_fstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out, - int _Prot = ios_base::_Default_open_prot) - : _Mybase(_STD addressof(_Filebuffer)) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) { - _Myios::setstate(ios_base::failbit); - } - } -#endif // _NATIVE_WCHAR_T_DEFINED - explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension basic_fstream(basic_fstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) { @@ -1294,25 +1166,6 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#ifdef _NATIVE_WCHAR_T_DEFINED - void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out, - int _Prot = ios_base::_Default_open_prot) { - // in standard as const std::filesystem::path::value_type *; _Prot is an extension - if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) { - _Myios::setstate(ios_base::failbit); - } else { - _Myios::clear(); - } - } - -#if _HAS_OLD_IOSTREAMS_MEMBERS - void open(const unsigned short* _Filename, ios_base::open_mode _Mode) { - // in standard as const std::filesystem::path::value_type * - open(_Filename, static_cast(_Mode)); - } -#endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // _NATIVE_WCHAR_T_DEFINED - __CLR_OR_THIS_CALL ~basic_fstream() noexcept override {} _NODISCARD _Myfb* rdbuf() const { diff --git a/stl/inc/iosfwd b/stl/inc/iosfwd index 9a55c45c15f..1691f6a644d 100644 --- a/stl/inc/iosfwd +++ b/stl/inc/iosfwd @@ -155,10 +155,6 @@ template <> struct char_traits; template <> struct char_traits; -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -struct char_traits; -#endif // _NATIVE_WCHAR_T_DEFINED template class allocator; diff --git a/stl/inc/xlocale b/stl/inc/xlocale index 29d93f06890..c287b72fb11 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -472,17 +472,6 @@ inline char __CRTDECL _Maklocbyte(wchar_t _Char, const _Locinfo::_Cvtvec& _Cvt) return _Byte; } -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Cvt) { - // convert unsigned short to char using _Cvtvec - char _Byte = '\0'; - mbstate_t _Mbst1 = {}; - _Wcrtomb(&_Byte, static_cast(_Char), &_Mbst1, &_Cvt); - return _Byte; -} -#endif // _NATIVE_WCHAR_T_DEFINED - template _Elem __CRTDECL _Maklocchr(char _Byte, _Elem*, const _Locinfo::_Cvtvec&) { // convert char to _Elem using _Cvtvec @@ -498,17 +487,6 @@ inline wchar_t __CRTDECL _Maklocchr(char _Byte, wchar_t*, const _Locinfo::_Cvtve return _Wc; } -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { - // convert char to unsigned short using _Cvtvec - unsigned short _Wc = 0; - mbstate_t _Mbst1 = {}; - _Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst1, &_Cvt); - return _Wc; -} -#endif // _NATIVE_WCHAR_T_DEFINED - template _Elem* __CRTDECL _Maklocstr(const char* _Ptr, _Elem*, const _Locinfo::_Cvtvec&) { // convert C string to _Elem sequence using _Cvtvec @@ -567,46 +545,6 @@ inline wchar_t* __CRTDECL _Maklocstr(const char* _Ptr, wchar_t*, const _Locinfo: return _Ptrdest; } -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { - // convert C string to unsigned short sequence using _Cvtvec - size_t _Count; - size_t _Count1; - size_t _Wchars; - const char* _Ptr1; - int _Bytes; - unsigned short _Wc; - mbstate_t _Mbst1 = {}; - - _Count1 = _CSTD strlen(_Ptr) + 1; - for (_Count = _Count1, _Wchars = 0, _Ptr1 = _Ptr; 0 < _Count; _Count -= _Bytes, _Ptr1 += _Bytes, ++_Wchars) { - if ((_Bytes = _Mbrtowc(reinterpret_cast(&_Wc), _Ptr1, _Count, &_Mbst1, &_Cvt)) <= 0) { - break; - } - } - - ++_Wchars; // count terminating nul - - wchar_t* _Ptrdest = static_cast(_calloc_dbg(_Wchars, sizeof(wchar_t), _CRT_BLOCK, __FILE__, __LINE__)); - - if (!_Ptrdest) { - _Xbad_alloc(); - } - - wchar_t* _Ptrnext = _Ptrdest; - mbstate_t _Mbst2 = {}; - for (; 0 < _Wchars; _Count -= _Bytes, _Ptr += _Bytes, --_Wchars, ++_Ptrnext) { - if ((_Bytes = _Mbrtowc(_Ptrnext, _Ptr, _Count1, &_Mbst2, &_Cvt)) <= 0) { - break; - } - } - - *_Ptrnext = L'\0'; - return reinterpret_cast(_Ptrdest); -} -#endif // _NATIVE_WCHAR_T_DEFINED - class _CRTIMP2_PURE_IMPORT codecvt_base : public locale::facet { // base class for codecvt public: enum { // constants for different parse states @@ -2103,208 +2041,6 @@ private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -class _CRTIMP2_PURE_IMPORT codecvt : public codecvt_base { - // facet for converting between unsigned short and char sequences -public: - using intern_type = unsigned short; - using extern_type = char; - using state_type = mbstate_t; - - result __CLR_OR_THIS_CALL in(mbstate_t& _State, const char* _First1, const char* _Last1, const char*& _Mid1, - unsigned short* _First2, unsigned short* _Last2, unsigned short*& _Mid2) const { - // convert bytes [_First1, _Last1) to [_First2, _Last2) - return do_in(_State, _First1, _Last1, _Mid1, _First2, _Last2, _Mid2); - } - - result __CLR_OR_THIS_CALL out(mbstate_t& _State, const unsigned short* _First1, const unsigned short* _Last1, - const unsigned short*& _Mid1, char* _First2, char* _Last2, char*& _Mid2) const { - // convert [_First1, _Last1) to bytes [_First2, _Last2) - return do_out(_State, _First1, _Last1, _Mid1, _First2, _Last2, _Mid2); - } - - result __CLR_OR_THIS_CALL unshift(mbstate_t& _State, char* _First2, char* _Last2, char*& _Mid2) const { - // generate bytes to return to default shift state - return do_unshift(_State, _First2, _Last2, _Mid2); - } - - int __CLR_OR_THIS_CALL length(mbstate_t& _State, const char* _First1, const char* _Last1, size_t _Count) const { - // return p - _First1, for the largest value p in [_First1, _Last1] such that [_First1, p) successfully - // converts to at most _Count _Elems - return do_length(_State, _First1, _Last1, _Count); - } - - __PURE_APPDOMAIN_GLOBAL static locale::id id; - - explicit __CLR_OR_THIS_CALL codecvt(size_t _Refs = 0) : codecvt_base(_Refs) { - _BEGIN_LOCINFO(_Lobj) - _Init(_Lobj); - _END_LOCINFO() - } - - explicit __CLR_OR_THIS_CALL codecvt(const _Locinfo& _Lobj, size_t _Refs = 0) : codecvt_base(_Refs) { - _Init(_Lobj); - } - - static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet** _Ppf = nullptr, const locale* _Ploc = nullptr) { - // return locale category mask and construct standard facet - if (_Ppf && !*_Ppf) { - *_Ppf = new codecvt(_Locinfo(_Ploc->c_str())); - } - - return _X_CTYPE; - } - -protected: - __CLR_OR_THIS_CALL ~codecvt() noexcept override {} - - void __CLR_OR_THIS_CALL _Init(const _Locinfo& _Lobj) { // initialize from _Lobj - _Cvt = _Lobj._Getcvt(); - } - - virtual result __CLR_OR_THIS_CALL do_in(mbstate_t&, const char* _First1, const char* _Last1, const char*& _Mid1, - unsigned short* _First2, unsigned short* _Last2, unsigned short*& _Mid2) const { - // convert bytes [_First1, _Last1) to [_First2, _Last2) - mbstate_t _Mystate{}; - _Adl_verify_range(_First1, _Last1); - _Adl_verify_range(_First2, _Last2); - _Mid1 = _First1; - _Mid2 = _First2; - for (;;) { - if (_Mid1 == _Last1) { - return ok; - } - - if (_Mid2 == _Last2) { - return partial; - } - - int _Bytes = _Mbrtowc( - reinterpret_cast(_Mid2), _Mid1, static_cast(_Last1 - _Mid1), &_Mystate, &_Cvt); - switch (_Bytes) { - case -2: // partial conversion - return partial; - - case -1: // failed conversion - return error; - - case 0: // converted NULL character, TRANSITION, VSO-654347 - _Bytes = 1; - // [[fallthrough]]; - - default: // converted some other character - _Mid1 += _Bytes; - ++_Mid2; - break; - } - } - } - - virtual result __CLR_OR_THIS_CALL do_out(mbstate_t& _State, const unsigned short* _First1, - const unsigned short* _Last1, const unsigned short*& _Mid1, char* _First2, char* _Last2, char*& _Mid2) const { - // convert [_First1, _Last1) to bytes [_First2, _Last2) - _Adl_verify_range(_First1, _Last1); - _Adl_verify_range(_First2, _Last2); - _Mid1 = _First1; - _Mid2 = _First2; - int _Bytes; - - while (_Mid1 != _Last1 && _Mid2 != _Last2) { - if (MB_LEN_MAX <= _Last2 - _Mid2) { - if ((_Bytes = _Wcrtomb(_Mid2, *_Mid1, &_State, &_Cvt)) < 0) { - return error; // locale-specific wcrtomb failed - } else { - ++_Mid1; - _Mid2 += _Bytes; - } - } else { // destination too small, convert into buffer - char _Buf[MB_LEN_MAX]; - mbstate_t _Stsave = _State; - - if ((_Bytes = _Wcrtomb(_Buf, *_Mid1, &_State, &_Cvt)) < 0) { - return error; // locale-specific wcrtomb failed - } else if (_Last2 - _Mid2 < _Bytes) { // converted too many, roll back and return previous - _State = _Stsave; - break; - } else { // copy converted bytes from buffer - _CSTD memcpy(_Mid2, _Buf, static_cast(_Bytes)); - ++_Mid1; - _Mid2 += _Bytes; - } - } - } - - return _Mid1 == _Last1 ? ok : partial; - } - - virtual result __CLR_OR_THIS_CALL do_unshift(mbstate_t& _State, char* _First2, char* _Last2, char*& _Mid2) const { - // generate bytes to return to default shift state - _Adl_verify_range(_First2, _Last2); - _Mid2 = _First2; - result _Ans = ok; - int _Bytes; - char _Buf[MB_LEN_MAX]; - mbstate_t _Stsave = _State; - - if ((_Bytes = _Wcrtomb(_Buf, L'\0', &_State, &_Cvt)) <= 0) { - _Ans = error; // locale-specific wcrtomb failed - } else if (_Last2 - _Mid2 < --_Bytes) { // converted too many, roll back and return - _State = _Stsave; - _Ans = partial; - } else if (0 < _Bytes) { // copy converted bytes from buffer - _CSTD memcpy(_Mid2, _Buf, static_cast(_Bytes)); - _Mid2 += _Bytes; - } - - return _Ans; - } - - virtual int __CLR_OR_THIS_CALL do_length( - mbstate_t& _State, const char* _First1, const char* _Last1, size_t _Count) const { - // return p - _First1, for the largest value p in [_First1, _Last1] such that [_First1, p) successfully - // converts to at most _Count wide characters - _Adl_verify_range(_First1, _Last1); - const auto _Old_first1 = _First1; - - for (; _Count > 0u && _First1 != _Last1; --_Count) { - wchar_t _Ch; - int _Bytes = _Mbrtowc(&_Ch, _First1, static_cast(_Last1 - _First1), &_State, &_Cvt); - if (_Bytes < 0) { // partial or failed conversion - break; - } - - if (_Bytes == 0) { // converted NULL character, TRANSITION, VSO-654347 - _Bytes = 1; - } - - // converted _Bytes bytes to a wide character - _First1 += _Bytes; - } - - return static_cast((_STD min) (_First1 - _Old_first1, ptrdiff_t{INT_MAX})); - } - - bool __CLR_OR_THIS_CALL do_always_noconv() const noexcept override { - // return true if conversions never change input - return false; - } - - int __CLR_OR_THIS_CALL do_max_length() const noexcept override { - // return maximum length required for a conversion (from codecvt) - return static_cast(_Cvt._Mbcurmax); - } - - int __CLR_OR_THIS_CALL do_encoding() const noexcept override { - // return length of code sequence (from codecvt) - return _Cvt._Mbcurmax == 1u; // 0 => varying length, 1 => fixed length - } - -private: - _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb -}; -#endif // _NATIVE_WCHAR_T_DEFINED - template class codecvt_byname : public codecvt<_Elem, _Byte, _Statype> { // codecvt for named locale public: @@ -2991,214 +2727,6 @@ private: _Locinfo::_Cvtvec _Cvt; // conversion information }; -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -class _CRTIMP2_PURE_IMPORT ctype - : public ctype_base { // facet for classifying unsigned short elements, converting cases -public: - using _Elem = unsigned short; - using char_type = _Elem; - - bool __CLR_OR_THIS_CALL is(mask _Maskval, _Elem _Ch) const { // test if element fits any mask classifications - return do_is(_Maskval, _Ch); - } - - const _Elem* __CLR_OR_THIS_CALL is(const _Elem* _First, const _Elem* _Last, - mask* _Dest) const { // get mask sequence for elements in [_First, _Last) - return do_is(_First, _Last, _Dest); - } - - const _Elem* __CLR_OR_THIS_CALL scan_is(mask _Maskval, const _Elem* _First, - const _Elem* _Last) const { // find first in [_First, _Last) that fits mask classification - return do_scan_is(_Maskval, _First, _Last); - } - - const _Elem* __CLR_OR_THIS_CALL scan_not(mask _Maskval, const _Elem* _First, - const _Elem* _Last) const { // find first in [_First, _Last) not fitting mask classification - return do_scan_not(_Maskval, _First, _Last); - } - - _Elem __CLR_OR_THIS_CALL tolower(_Elem _Ch) const { // convert element to lower case - return do_tolower(_Ch); - } - - const _Elem* __CLR_OR_THIS_CALL tolower( - _Elem* _First, const _Elem* _Last) const { // convert [_First, _Last) in place to lower case - return do_tolower(_First, _Last); - } - - _Elem __CLR_OR_THIS_CALL toupper(_Elem _Ch) const { // convert element to upper case - return do_toupper(_Ch); - } - - const _Elem* __CLR_OR_THIS_CALL toupper( - _Elem* _First, const _Elem* _Last) const { // convert [_First, _Last) in place to upper case - return do_toupper(_First, _Last); - } - - _Elem __CLR_OR_THIS_CALL widen(char _Byte) const { // widen char - return do_widen(_Byte); - } - - const char* __CLR_OR_THIS_CALL widen(const char* _First, const char* _Last, - _Elem* _Dest) const { // widen chars in [_First, _Last) - return do_widen(_First, _Last, _Dest); - } - - char __CLR_OR_THIS_CALL narrow(_Elem _Ch, char _Dflt = '\0') const { // narrow element to char - return do_narrow(_Ch, _Dflt); - } - - const _Elem* __CLR_OR_THIS_CALL narrow(const _Elem* _First, const _Elem* _Last, char _Dflt, - char* _Dest) const { // narrow elements in [_First, _Last) to chars - return do_narrow(_First, _Last, _Dflt, _Dest); - } - - __PURE_APPDOMAIN_GLOBAL static locale::id id; - - explicit __CLR_OR_THIS_CALL ctype(size_t _Refs = 0) : ctype_base(_Refs) { - _BEGIN_LOCINFO(_Lobj) - _Init(_Lobj); - _END_LOCINFO() - } - - __CLR_OR_THIS_CALL ctype(const _Locinfo& _Lobj, size_t _Refs = 0) : ctype_base(_Refs) { - _Init(_Lobj); - } - - static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet** _Ppf = nullptr, const locale* _Ploc = nullptr) { - if (_Ppf && !*_Ppf) { - *_Ppf = new ctype<_Elem>(_Locinfo(_Ploc->c_str())); - } - - return _X_CTYPE; - } - -protected: - __CLR_OR_THIS_CALL ~ctype() noexcept override { - if (_Ctype._Delfl) { - _CSTD free(const_cast(_Ctype._Table)); - } - - _CSTD free(_Ctype._LocaleName); - } - - void __CLR_OR_THIS_CALL _Init(const _Locinfo& _Lobj) { // initialize from _Lobj - _Ctype = _Lobj._Getctype(); - _Cvt = _Lobj._Getcvt(); - } - - virtual bool __CLR_OR_THIS_CALL do_is( - mask _Maskval, _Elem _Ch) const { // test if element fits any mask classifications - return (_CSTD _Getwctype(_Ch, &_Ctype) & _Maskval) != 0; - } - - virtual const _Elem* __CLR_OR_THIS_CALL do_is(const _Elem* _First, const _Elem* _Last, - mask* _Dest) const { // get mask sequence for elements in [_First, _Last) - _Adl_verify_range(_First, _Last); - return reinterpret_cast(_CSTD _Getwctypes( - reinterpret_cast(_First), reinterpret_cast(_Last), _Dest, &_Ctype)); - } - - virtual const _Elem* __CLR_OR_THIS_CALL do_scan_is(mask _Maskval, const _Elem* _First, - const _Elem* _Last) const { // find first in [_First, _Last) that fits mask classification - _Adl_verify_range(_First, _Last); - while (_First != _Last && !is(_Maskval, *_First)) { - ++_First; - } - - return _First; - } - - virtual const _Elem* __CLR_OR_THIS_CALL do_scan_not(mask _Maskval, const _Elem* _First, - const _Elem* _Last) const { // find first in [_First, _Last) not fitting mask classification - _Adl_verify_range(_First, _Last); - while (_First != _Last && is(_Maskval, *_First)) { - ++_First; - } - - return _First; - } - - virtual _Elem __CLR_OR_THIS_CALL do_tolower(_Elem _Ch) const { // convert element to lower case - return _Towlower(_Ch, &_Ctype); - } - - virtual const _Elem* __CLR_OR_THIS_CALL do_tolower(_Elem* _First, - const _Elem* _Last) const { // convert [_First, _Last) in place to lower case - _Adl_verify_range(_First, _Last); - for (; _First != _Last; ++_First) { - *_First = _Towlower(*_First, &_Ctype); - } - - return _First; - } - - virtual _Elem __CLR_OR_THIS_CALL do_toupper(_Elem _Ch) const { // convert element to upper case - return _Towupper(_Ch, &_Ctype); - } - - virtual const _Elem* __CLR_OR_THIS_CALL do_toupper(_Elem* _First, - const _Elem* _Last) const { // convert [_First, _Last) in place to upper case - _Adl_verify_range(_First, _Last); - for (; _First != _Last; ++_First) { - *_First = _Towupper(*_First, &_Ctype); - } - - return _First; - } - - _Elem __CLR_OR_THIS_CALL _Dowiden(char _Byte) const { // widen char - mbstate_t _Mbst = {}; - unsigned short _Wc; - - if (_Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst, &_Cvt) < 0) { - return static_cast(WEOF); - } - - return _Wc; - } - - virtual _Elem __CLR_OR_THIS_CALL do_widen(char _Byte) const { // widen char - return _Dowiden(_Byte); - } - - virtual const char* __CLR_OR_THIS_CALL do_widen( - const char* _First, const char* _Last, _Elem* _Dest) const { // widen chars in [_First, _Last) - _Adl_verify_range(_First, _Last); - for (; _First != _Last; ++_First, ++_Dest) { - *_Dest = _Dowiden(*_First); - } - - return _First; - } - - char __CLR_OR_THIS_CALL _Donarrow(_Elem _Ch, char _Dflt) const { // narrow element to char - char _Buf[MB_LEN_MAX]; - mbstate_t _Mbst = {}; - return _Wcrtomb(_Buf, _Ch, &_Mbst, &_Cvt) != 1 ? _Dflt : _Buf[0]; - } - - virtual char __CLR_OR_THIS_CALL do_narrow(_Elem _Ch, char _Dflt) const { // narrow element to char - return _Donarrow(_Ch, _Dflt); - } - - virtual const _Elem* __CLR_OR_THIS_CALL do_narrow(const _Elem* _First, const _Elem* _Last, char _Dflt, - char* _Dest) const { // narrow elements in [_First, _Last) to chars - _Adl_verify_range(_First, _Last); - for (; _First != _Last; ++_First, ++_Dest) { - *_Dest = _Donarrow(*_First, _Dflt); - } - - return _First; - } - -private: - _Locinfo::_Ctypevec _Ctype; // locale info passed to _Tolower, etc. - _Locinfo::_Cvtvec _Cvt; // conversion information -}; -#endif // _NATIVE_WCHAR_T_DEFINED - template class ctype_byname : public ctype<_Elem> { // ctype for named locale public: diff --git a/stl/inc/xstring b/stl/inc/xstring index 481e0cebcd7..cf09cc5c782 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -340,11 +340,6 @@ using u32streampos = streampos; template <> struct char_traits : _WChar_traits {}; -#ifdef _NATIVE_WCHAR_T_DEFINED -template <> -struct char_traits : _WChar_traits {}; -#endif // _NATIVE_WCHAR_T_DEFINED - #if defined(__cpp_char8_t) && !defined(__EDG__) && !defined(__clang__) #define _HAS_U8_INTRINSICS 1 #else // ^^^ Use intrinsics for char8_t / don't use said intrinsics vvv From 72cb217c98b93f0611fedb0dd72f592ac43b4bde Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 28 Aug 2021 15:49:48 +0700 Subject: [PATCH 2/9] restore stl/inc/xlocale --- stl/inc/xlocale | 472 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) diff --git a/stl/inc/xlocale b/stl/inc/xlocale index c287b72fb11..29d93f06890 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -472,6 +472,17 @@ inline char __CRTDECL _Maklocbyte(wchar_t _Char, const _Locinfo::_Cvtvec& _Cvt) return _Byte; } +#ifdef _NATIVE_WCHAR_T_DEFINED +template <> +inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Cvt) { + // convert unsigned short to char using _Cvtvec + char _Byte = '\0'; + mbstate_t _Mbst1 = {}; + _Wcrtomb(&_Byte, static_cast(_Char), &_Mbst1, &_Cvt); + return _Byte; +} +#endif // _NATIVE_WCHAR_T_DEFINED + template _Elem __CRTDECL _Maklocchr(char _Byte, _Elem*, const _Locinfo::_Cvtvec&) { // convert char to _Elem using _Cvtvec @@ -487,6 +498,17 @@ inline wchar_t __CRTDECL _Maklocchr(char _Byte, wchar_t*, const _Locinfo::_Cvtve return _Wc; } +#ifdef _NATIVE_WCHAR_T_DEFINED +template <> +inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { + // convert char to unsigned short using _Cvtvec + unsigned short _Wc = 0; + mbstate_t _Mbst1 = {}; + _Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst1, &_Cvt); + return _Wc; +} +#endif // _NATIVE_WCHAR_T_DEFINED + template _Elem* __CRTDECL _Maklocstr(const char* _Ptr, _Elem*, const _Locinfo::_Cvtvec&) { // convert C string to _Elem sequence using _Cvtvec @@ -545,6 +567,46 @@ inline wchar_t* __CRTDECL _Maklocstr(const char* _Ptr, wchar_t*, const _Locinfo: return _Ptrdest; } +#ifdef _NATIVE_WCHAR_T_DEFINED +template <> +inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { + // convert C string to unsigned short sequence using _Cvtvec + size_t _Count; + size_t _Count1; + size_t _Wchars; + const char* _Ptr1; + int _Bytes; + unsigned short _Wc; + mbstate_t _Mbst1 = {}; + + _Count1 = _CSTD strlen(_Ptr) + 1; + for (_Count = _Count1, _Wchars = 0, _Ptr1 = _Ptr; 0 < _Count; _Count -= _Bytes, _Ptr1 += _Bytes, ++_Wchars) { + if ((_Bytes = _Mbrtowc(reinterpret_cast(&_Wc), _Ptr1, _Count, &_Mbst1, &_Cvt)) <= 0) { + break; + } + } + + ++_Wchars; // count terminating nul + + wchar_t* _Ptrdest = static_cast(_calloc_dbg(_Wchars, sizeof(wchar_t), _CRT_BLOCK, __FILE__, __LINE__)); + + if (!_Ptrdest) { + _Xbad_alloc(); + } + + wchar_t* _Ptrnext = _Ptrdest; + mbstate_t _Mbst2 = {}; + for (; 0 < _Wchars; _Count -= _Bytes, _Ptr += _Bytes, --_Wchars, ++_Ptrnext) { + if ((_Bytes = _Mbrtowc(_Ptrnext, _Ptr, _Count1, &_Mbst2, &_Cvt)) <= 0) { + break; + } + } + + *_Ptrnext = L'\0'; + return reinterpret_cast(_Ptrdest); +} +#endif // _NATIVE_WCHAR_T_DEFINED + class _CRTIMP2_PURE_IMPORT codecvt_base : public locale::facet { // base class for codecvt public: enum { // constants for different parse states @@ -2041,6 +2103,208 @@ private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; +#ifdef _NATIVE_WCHAR_T_DEFINED +template <> +class _CRTIMP2_PURE_IMPORT codecvt : public codecvt_base { + // facet for converting between unsigned short and char sequences +public: + using intern_type = unsigned short; + using extern_type = char; + using state_type = mbstate_t; + + result __CLR_OR_THIS_CALL in(mbstate_t& _State, const char* _First1, const char* _Last1, const char*& _Mid1, + unsigned short* _First2, unsigned short* _Last2, unsigned short*& _Mid2) const { + // convert bytes [_First1, _Last1) to [_First2, _Last2) + return do_in(_State, _First1, _Last1, _Mid1, _First2, _Last2, _Mid2); + } + + result __CLR_OR_THIS_CALL out(mbstate_t& _State, const unsigned short* _First1, const unsigned short* _Last1, + const unsigned short*& _Mid1, char* _First2, char* _Last2, char*& _Mid2) const { + // convert [_First1, _Last1) to bytes [_First2, _Last2) + return do_out(_State, _First1, _Last1, _Mid1, _First2, _Last2, _Mid2); + } + + result __CLR_OR_THIS_CALL unshift(mbstate_t& _State, char* _First2, char* _Last2, char*& _Mid2) const { + // generate bytes to return to default shift state + return do_unshift(_State, _First2, _Last2, _Mid2); + } + + int __CLR_OR_THIS_CALL length(mbstate_t& _State, const char* _First1, const char* _Last1, size_t _Count) const { + // return p - _First1, for the largest value p in [_First1, _Last1] such that [_First1, p) successfully + // converts to at most _Count _Elems + return do_length(_State, _First1, _Last1, _Count); + } + + __PURE_APPDOMAIN_GLOBAL static locale::id id; + + explicit __CLR_OR_THIS_CALL codecvt(size_t _Refs = 0) : codecvt_base(_Refs) { + _BEGIN_LOCINFO(_Lobj) + _Init(_Lobj); + _END_LOCINFO() + } + + explicit __CLR_OR_THIS_CALL codecvt(const _Locinfo& _Lobj, size_t _Refs = 0) : codecvt_base(_Refs) { + _Init(_Lobj); + } + + static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet** _Ppf = nullptr, const locale* _Ploc = nullptr) { + // return locale category mask and construct standard facet + if (_Ppf && !*_Ppf) { + *_Ppf = new codecvt(_Locinfo(_Ploc->c_str())); + } + + return _X_CTYPE; + } + +protected: + __CLR_OR_THIS_CALL ~codecvt() noexcept override {} + + void __CLR_OR_THIS_CALL _Init(const _Locinfo& _Lobj) { // initialize from _Lobj + _Cvt = _Lobj._Getcvt(); + } + + virtual result __CLR_OR_THIS_CALL do_in(mbstate_t&, const char* _First1, const char* _Last1, const char*& _Mid1, + unsigned short* _First2, unsigned short* _Last2, unsigned short*& _Mid2) const { + // convert bytes [_First1, _Last1) to [_First2, _Last2) + mbstate_t _Mystate{}; + _Adl_verify_range(_First1, _Last1); + _Adl_verify_range(_First2, _Last2); + _Mid1 = _First1; + _Mid2 = _First2; + for (;;) { + if (_Mid1 == _Last1) { + return ok; + } + + if (_Mid2 == _Last2) { + return partial; + } + + int _Bytes = _Mbrtowc( + reinterpret_cast(_Mid2), _Mid1, static_cast(_Last1 - _Mid1), &_Mystate, &_Cvt); + switch (_Bytes) { + case -2: // partial conversion + return partial; + + case -1: // failed conversion + return error; + + case 0: // converted NULL character, TRANSITION, VSO-654347 + _Bytes = 1; + // [[fallthrough]]; + + default: // converted some other character + _Mid1 += _Bytes; + ++_Mid2; + break; + } + } + } + + virtual result __CLR_OR_THIS_CALL do_out(mbstate_t& _State, const unsigned short* _First1, + const unsigned short* _Last1, const unsigned short*& _Mid1, char* _First2, char* _Last2, char*& _Mid2) const { + // convert [_First1, _Last1) to bytes [_First2, _Last2) + _Adl_verify_range(_First1, _Last1); + _Adl_verify_range(_First2, _Last2); + _Mid1 = _First1; + _Mid2 = _First2; + int _Bytes; + + while (_Mid1 != _Last1 && _Mid2 != _Last2) { + if (MB_LEN_MAX <= _Last2 - _Mid2) { + if ((_Bytes = _Wcrtomb(_Mid2, *_Mid1, &_State, &_Cvt)) < 0) { + return error; // locale-specific wcrtomb failed + } else { + ++_Mid1; + _Mid2 += _Bytes; + } + } else { // destination too small, convert into buffer + char _Buf[MB_LEN_MAX]; + mbstate_t _Stsave = _State; + + if ((_Bytes = _Wcrtomb(_Buf, *_Mid1, &_State, &_Cvt)) < 0) { + return error; // locale-specific wcrtomb failed + } else if (_Last2 - _Mid2 < _Bytes) { // converted too many, roll back and return previous + _State = _Stsave; + break; + } else { // copy converted bytes from buffer + _CSTD memcpy(_Mid2, _Buf, static_cast(_Bytes)); + ++_Mid1; + _Mid2 += _Bytes; + } + } + } + + return _Mid1 == _Last1 ? ok : partial; + } + + virtual result __CLR_OR_THIS_CALL do_unshift(mbstate_t& _State, char* _First2, char* _Last2, char*& _Mid2) const { + // generate bytes to return to default shift state + _Adl_verify_range(_First2, _Last2); + _Mid2 = _First2; + result _Ans = ok; + int _Bytes; + char _Buf[MB_LEN_MAX]; + mbstate_t _Stsave = _State; + + if ((_Bytes = _Wcrtomb(_Buf, L'\0', &_State, &_Cvt)) <= 0) { + _Ans = error; // locale-specific wcrtomb failed + } else if (_Last2 - _Mid2 < --_Bytes) { // converted too many, roll back and return + _State = _Stsave; + _Ans = partial; + } else if (0 < _Bytes) { // copy converted bytes from buffer + _CSTD memcpy(_Mid2, _Buf, static_cast(_Bytes)); + _Mid2 += _Bytes; + } + + return _Ans; + } + + virtual int __CLR_OR_THIS_CALL do_length( + mbstate_t& _State, const char* _First1, const char* _Last1, size_t _Count) const { + // return p - _First1, for the largest value p in [_First1, _Last1] such that [_First1, p) successfully + // converts to at most _Count wide characters + _Adl_verify_range(_First1, _Last1); + const auto _Old_first1 = _First1; + + for (; _Count > 0u && _First1 != _Last1; --_Count) { + wchar_t _Ch; + int _Bytes = _Mbrtowc(&_Ch, _First1, static_cast(_Last1 - _First1), &_State, &_Cvt); + if (_Bytes < 0) { // partial or failed conversion + break; + } + + if (_Bytes == 0) { // converted NULL character, TRANSITION, VSO-654347 + _Bytes = 1; + } + + // converted _Bytes bytes to a wide character + _First1 += _Bytes; + } + + return static_cast((_STD min) (_First1 - _Old_first1, ptrdiff_t{INT_MAX})); + } + + bool __CLR_OR_THIS_CALL do_always_noconv() const noexcept override { + // return true if conversions never change input + return false; + } + + int __CLR_OR_THIS_CALL do_max_length() const noexcept override { + // return maximum length required for a conversion (from codecvt) + return static_cast(_Cvt._Mbcurmax); + } + + int __CLR_OR_THIS_CALL do_encoding() const noexcept override { + // return length of code sequence (from codecvt) + return _Cvt._Mbcurmax == 1u; // 0 => varying length, 1 => fixed length + } + +private: + _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb +}; +#endif // _NATIVE_WCHAR_T_DEFINED + template class codecvt_byname : public codecvt<_Elem, _Byte, _Statype> { // codecvt for named locale public: @@ -2727,6 +2991,214 @@ private: _Locinfo::_Cvtvec _Cvt; // conversion information }; +#ifdef _NATIVE_WCHAR_T_DEFINED +template <> +class _CRTIMP2_PURE_IMPORT ctype + : public ctype_base { // facet for classifying unsigned short elements, converting cases +public: + using _Elem = unsigned short; + using char_type = _Elem; + + bool __CLR_OR_THIS_CALL is(mask _Maskval, _Elem _Ch) const { // test if element fits any mask classifications + return do_is(_Maskval, _Ch); + } + + const _Elem* __CLR_OR_THIS_CALL is(const _Elem* _First, const _Elem* _Last, + mask* _Dest) const { // get mask sequence for elements in [_First, _Last) + return do_is(_First, _Last, _Dest); + } + + const _Elem* __CLR_OR_THIS_CALL scan_is(mask _Maskval, const _Elem* _First, + const _Elem* _Last) const { // find first in [_First, _Last) that fits mask classification + return do_scan_is(_Maskval, _First, _Last); + } + + const _Elem* __CLR_OR_THIS_CALL scan_not(mask _Maskval, const _Elem* _First, + const _Elem* _Last) const { // find first in [_First, _Last) not fitting mask classification + return do_scan_not(_Maskval, _First, _Last); + } + + _Elem __CLR_OR_THIS_CALL tolower(_Elem _Ch) const { // convert element to lower case + return do_tolower(_Ch); + } + + const _Elem* __CLR_OR_THIS_CALL tolower( + _Elem* _First, const _Elem* _Last) const { // convert [_First, _Last) in place to lower case + return do_tolower(_First, _Last); + } + + _Elem __CLR_OR_THIS_CALL toupper(_Elem _Ch) const { // convert element to upper case + return do_toupper(_Ch); + } + + const _Elem* __CLR_OR_THIS_CALL toupper( + _Elem* _First, const _Elem* _Last) const { // convert [_First, _Last) in place to upper case + return do_toupper(_First, _Last); + } + + _Elem __CLR_OR_THIS_CALL widen(char _Byte) const { // widen char + return do_widen(_Byte); + } + + const char* __CLR_OR_THIS_CALL widen(const char* _First, const char* _Last, + _Elem* _Dest) const { // widen chars in [_First, _Last) + return do_widen(_First, _Last, _Dest); + } + + char __CLR_OR_THIS_CALL narrow(_Elem _Ch, char _Dflt = '\0') const { // narrow element to char + return do_narrow(_Ch, _Dflt); + } + + const _Elem* __CLR_OR_THIS_CALL narrow(const _Elem* _First, const _Elem* _Last, char _Dflt, + char* _Dest) const { // narrow elements in [_First, _Last) to chars + return do_narrow(_First, _Last, _Dflt, _Dest); + } + + __PURE_APPDOMAIN_GLOBAL static locale::id id; + + explicit __CLR_OR_THIS_CALL ctype(size_t _Refs = 0) : ctype_base(_Refs) { + _BEGIN_LOCINFO(_Lobj) + _Init(_Lobj); + _END_LOCINFO() + } + + __CLR_OR_THIS_CALL ctype(const _Locinfo& _Lobj, size_t _Refs = 0) : ctype_base(_Refs) { + _Init(_Lobj); + } + + static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet** _Ppf = nullptr, const locale* _Ploc = nullptr) { + if (_Ppf && !*_Ppf) { + *_Ppf = new ctype<_Elem>(_Locinfo(_Ploc->c_str())); + } + + return _X_CTYPE; + } + +protected: + __CLR_OR_THIS_CALL ~ctype() noexcept override { + if (_Ctype._Delfl) { + _CSTD free(const_cast(_Ctype._Table)); + } + + _CSTD free(_Ctype._LocaleName); + } + + void __CLR_OR_THIS_CALL _Init(const _Locinfo& _Lobj) { // initialize from _Lobj + _Ctype = _Lobj._Getctype(); + _Cvt = _Lobj._Getcvt(); + } + + virtual bool __CLR_OR_THIS_CALL do_is( + mask _Maskval, _Elem _Ch) const { // test if element fits any mask classifications + return (_CSTD _Getwctype(_Ch, &_Ctype) & _Maskval) != 0; + } + + virtual const _Elem* __CLR_OR_THIS_CALL do_is(const _Elem* _First, const _Elem* _Last, + mask* _Dest) const { // get mask sequence for elements in [_First, _Last) + _Adl_verify_range(_First, _Last); + return reinterpret_cast(_CSTD _Getwctypes( + reinterpret_cast(_First), reinterpret_cast(_Last), _Dest, &_Ctype)); + } + + virtual const _Elem* __CLR_OR_THIS_CALL do_scan_is(mask _Maskval, const _Elem* _First, + const _Elem* _Last) const { // find first in [_First, _Last) that fits mask classification + _Adl_verify_range(_First, _Last); + while (_First != _Last && !is(_Maskval, *_First)) { + ++_First; + } + + return _First; + } + + virtual const _Elem* __CLR_OR_THIS_CALL do_scan_not(mask _Maskval, const _Elem* _First, + const _Elem* _Last) const { // find first in [_First, _Last) not fitting mask classification + _Adl_verify_range(_First, _Last); + while (_First != _Last && is(_Maskval, *_First)) { + ++_First; + } + + return _First; + } + + virtual _Elem __CLR_OR_THIS_CALL do_tolower(_Elem _Ch) const { // convert element to lower case + return _Towlower(_Ch, &_Ctype); + } + + virtual const _Elem* __CLR_OR_THIS_CALL do_tolower(_Elem* _First, + const _Elem* _Last) const { // convert [_First, _Last) in place to lower case + _Adl_verify_range(_First, _Last); + for (; _First != _Last; ++_First) { + *_First = _Towlower(*_First, &_Ctype); + } + + return _First; + } + + virtual _Elem __CLR_OR_THIS_CALL do_toupper(_Elem _Ch) const { // convert element to upper case + return _Towupper(_Ch, &_Ctype); + } + + virtual const _Elem* __CLR_OR_THIS_CALL do_toupper(_Elem* _First, + const _Elem* _Last) const { // convert [_First, _Last) in place to upper case + _Adl_verify_range(_First, _Last); + for (; _First != _Last; ++_First) { + *_First = _Towupper(*_First, &_Ctype); + } + + return _First; + } + + _Elem __CLR_OR_THIS_CALL _Dowiden(char _Byte) const { // widen char + mbstate_t _Mbst = {}; + unsigned short _Wc; + + if (_Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst, &_Cvt) < 0) { + return static_cast(WEOF); + } + + return _Wc; + } + + virtual _Elem __CLR_OR_THIS_CALL do_widen(char _Byte) const { // widen char + return _Dowiden(_Byte); + } + + virtual const char* __CLR_OR_THIS_CALL do_widen( + const char* _First, const char* _Last, _Elem* _Dest) const { // widen chars in [_First, _Last) + _Adl_verify_range(_First, _Last); + for (; _First != _Last; ++_First, ++_Dest) { + *_Dest = _Dowiden(*_First); + } + + return _First; + } + + char __CLR_OR_THIS_CALL _Donarrow(_Elem _Ch, char _Dflt) const { // narrow element to char + char _Buf[MB_LEN_MAX]; + mbstate_t _Mbst = {}; + return _Wcrtomb(_Buf, _Ch, &_Mbst, &_Cvt) != 1 ? _Dflt : _Buf[0]; + } + + virtual char __CLR_OR_THIS_CALL do_narrow(_Elem _Ch, char _Dflt) const { // narrow element to char + return _Donarrow(_Ch, _Dflt); + } + + virtual const _Elem* __CLR_OR_THIS_CALL do_narrow(const _Elem* _First, const _Elem* _Last, char _Dflt, + char* _Dest) const { // narrow elements in [_First, _Last) to chars + _Adl_verify_range(_First, _Last); + for (; _First != _Last; ++_First, ++_Dest) { + *_Dest = _Donarrow(*_First, _Dflt); + } + + return _First; + } + +private: + _Locinfo::_Ctypevec _Ctype; // locale info passed to _Tolower, etc. + _Locinfo::_Cvtvec _Cvt; // conversion information +}; +#endif // _NATIVE_WCHAR_T_DEFINED + template class ctype_byname : public ctype<_Elem> { // ctype for named locale public: From eb8a530b01a20629e5ace95cdf5abfa6d5517027 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 28 Aug 2021 21:08:52 +0700 Subject: [PATCH 3/9] restore unsigned short counterparts for stl build. --- stl/inc/fstream | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ stl/inc/iosfwd | 4 ++ stl/inc/xlocale | 24 ++++---- stl/inc/xstring | 5 ++ 4 files changed, 168 insertions(+), 12 deletions(-) diff --git a/stl/inc/fstream b/stl/inc/fstream index 090c699bb8c..e2eaaa0cee4 100644 --- a/stl/inc/fstream +++ b/stl/inc/fstream @@ -63,6 +63,10 @@ _INLINE_VAR constexpr bool _Is_any_path = _Is_any_of_v<_Ty extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int); extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int); +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const unsigned short*, ios_base::openmode, int); +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + template bool _Fgetc(_Elem& _Ch, FILE* _File) { // get an element from a C stream return _CSTD fread(&_Ch, sizeof(_Elem), 1, _File) == 1; @@ -90,6 +94,19 @@ inline bool _Fgetc(wchar_t& _Wchar, FILE* _File) { // get a wchar_t element from } } +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +template <> +inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) { // get an unsigned short element from a C stream + wint_t _Meta; + if ((_Meta = _CSTD fgetwc(_File)) == WEOF) { + return false; + } else { // got one, convert to unsigned short + _Wchar = static_cast(_Meta); + return true; + } +} +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + template bool _Fputc(_Elem _Ch, FILE* _File) { // put an element to a C stream return _CSTD fwrite(&_Ch, 1, sizeof(_Elem), _File) == sizeof(_Elem); @@ -105,6 +122,13 @@ inline bool _Fputc(wchar_t _Wchar, FILE* _File) { // put a wchar_t element to a return _CSTD fputwc(_Wchar, _File) != WEOF; } +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +template <> +inline bool _Fputc(unsigned short _Wchar, FILE* _File) { // put an unsigned short element to a C stream + return _CSTD fputwc(_Wchar, _File) != WEOF; +} +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + template bool _Ungetc(const _Elem&, FILE*) { // put back an arbitrary element to a C stream (always fail) return false; @@ -130,6 +154,13 @@ inline bool _Ungetc(const wchar_t& _Wchar, FILE* _File) { // put back a wchar_t return _CSTD ungetwc(_Wchar, _File) != WEOF; } +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +template <> +inline bool _Ungetc(const unsigned short& _Wchar, FILE* _File) { // put back an unsigned short element to a C stream + return _CSTD ungetwc(_Wchar, _File) != WEOF; +} +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + template class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer associated with a C stream public: @@ -322,6 +353,32 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + basic_filebuf* open( + const unsigned short* _Filename, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Myfile) { + return nullptr; + } + + const auto _File = _Fiopen(_Filename, _Mode, _Prot); + if (!_File) { + return nullptr; // open failed + } + + _Init(_File, _Openfl); + _Initcvt(_STD use_facet<_Cvt>(_Mysb::getloc())); + return this; // open succeeded + } + +#if _HAS_OLD_IOSTREAMS_MEMBERS + basic_filebuf* open(const unsigned short* _Filename, ios_base::open_mode _Mode) { + // in standard as const std::filesystem::path::value_type * + return open(_Filename, static_cast(_Mode)); + } +#endif // _HAS_OLD_IOSTREAMS_MEMBERS +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + basic_filebuf* close() { basic_filebuf* _Ans; if (_Myfile) { // put any homing sequence and close file @@ -786,6 +843,17 @@ public: const _Ty& _Path, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) : basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + explicit basic_ifstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in, + int _Prot = ios_base::_Default_open_prot) + : _Mybase(_STD addressof(_Filebuffer)) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) { + _Myios::setstate(ios_base::failbit); + } + } +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension basic_ifstream(basic_ifstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) { @@ -854,6 +922,25 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in, + int _Prot = ios_base::_Default_open_prot) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) { + _Myios::setstate(ios_base::failbit); + } else { + _Myios::clear(); + } + } + +#if _HAS_OLD_IOSTREAMS_MEMBERS + void open(const unsigned short* _Filename, ios_base::open_mode _Mode) { + // in standard as const std::filesystem::path::value_type * + open(_Filename, static_cast(_Mode)); + } +#endif // _HAS_OLD_IOSTREAMS_MEMBERS +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + __CLR_OR_THIS_CALL ~basic_ifstream() noexcept override {} _NODISCARD _Myfb* rdbuf() const { @@ -939,6 +1026,17 @@ public: const _Ty& _Path, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) : basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + explicit basic_ofstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out, + int _Prot = ios_base::_Default_open_prot) + : _Mybase(_STD addressof(_Filebuffer)) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) { + _Myios::setstate(ios_base::failbit); + } + } +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension basic_ofstream(basic_ofstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) { @@ -1007,6 +1105,25 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out, + int _Prot = ios_base::_Default_open_prot) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) { + _Myios::setstate(ios_base::failbit); + } else { + _Myios::clear(); + } + } + +#if _HAS_OLD_IOSTREAMS_MEMBERS + void open(const unsigned short* _Filename, ios_base::open_mode _Mode) { + // in standard as const std::filesystem::path::value_type * + open(_Filename, static_cast(_Mode)); + } +#endif // _HAS_OLD_IOSTREAMS_MEMBERS +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + __CLR_OR_THIS_CALL ~basic_ofstream() noexcept override {} _NODISCARD _Myfb* rdbuf() const { @@ -1097,6 +1214,17 @@ public: int _Prot = ios_base::_Default_open_prot) : basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + explicit basic_fstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out, + int _Prot = ios_base::_Default_open_prot) + : _Mybase(_STD addressof(_Filebuffer)) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) { + _Myios::setstate(ios_base::failbit); + } + } +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension basic_fstream(basic_fstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) { @@ -1166,6 +1294,25 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out, + int _Prot = ios_base::_Default_open_prot) { + // in standard as const std::filesystem::path::value_type *; _Prot is an extension + if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) { + _Myios::setstate(ios_base::failbit); + } else { + _Myios::clear(); + } + } + +#if _HAS_OLD_IOSTREAMS_MEMBERS + void open(const unsigned short* _Filename, ios_base::open_mode _Mode) { + // in standard as const std::filesystem::path::value_type * + open(_Filename, static_cast(_Mode)); + } +#endif // _HAS_OLD_IOSTREAMS_MEMBERS +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + __CLR_OR_THIS_CALL ~basic_fstream() noexcept override {} _NODISCARD _Myfb* rdbuf() const { diff --git a/stl/inc/iosfwd b/stl/inc/iosfwd index 1691f6a644d..25d9c4641b9 100644 --- a/stl/inc/iosfwd +++ b/stl/inc/iosfwd @@ -155,6 +155,10 @@ template <> struct char_traits; template <> struct char_traits; +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +template <> +struct char_traits; +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template class allocator; diff --git a/stl/inc/xlocale b/stl/inc/xlocale index 29d93f06890..be1bb5936d2 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -200,10 +200,10 @@ public: static void __CLRCALL_OR_CDECL _Makewloc( const _Locinfo&, category, _Locimp*, const locale*); // make wchar_t facets -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) static void __CLRCALL_OR_CDECL _Makeushloc( const _Locinfo&, category, _Locimp*, const locale*); // make ushort facets -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) static void __CLRCALL_OR_CDECL _Makexloc( const _Locinfo&, category, _Locimp*, const locale*); // make remaining facets @@ -472,7 +472,7 @@ inline char __CRTDECL _Maklocbyte(wchar_t _Char, const _Locinfo::_Cvtvec& _Cvt) return _Byte; } -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template <> inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Cvt) { // convert unsigned short to char using _Cvtvec @@ -481,7 +481,7 @@ inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Wcrtomb(&_Byte, static_cast(_Char), &_Mbst1, &_Cvt); return _Byte; } -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template _Elem __CRTDECL _Maklocchr(char _Byte, _Elem*, const _Locinfo::_Cvtvec&) { @@ -498,7 +498,7 @@ inline wchar_t __CRTDECL _Maklocchr(char _Byte, wchar_t*, const _Locinfo::_Cvtve return _Wc; } -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template <> inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { // convert char to unsigned short using _Cvtvec @@ -507,7 +507,7 @@ inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _L _Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst1, &_Cvt); return _Wc; } -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template _Elem* __CRTDECL _Maklocstr(const char* _Ptr, _Elem*, const _Locinfo::_Cvtvec&) { @@ -567,7 +567,7 @@ inline wchar_t* __CRTDECL _Maklocstr(const char* _Ptr, wchar_t*, const _Locinfo: return _Ptrdest; } -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template <> inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { // convert C string to unsigned short sequence using _Cvtvec @@ -605,7 +605,7 @@ inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, c *_Ptrnext = L'\0'; return reinterpret_cast(_Ptrdest); } -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) class _CRTIMP2_PURE_IMPORT codecvt_base : public locale::facet { // base class for codecvt public: @@ -2103,7 +2103,7 @@ private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template <> class _CRTIMP2_PURE_IMPORT codecvt : public codecvt_base { // facet for converting between unsigned short and char sequences @@ -2303,7 +2303,7 @@ protected: private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template class codecvt_byname : public codecvt<_Elem, _Byte, _Statype> { // codecvt for named locale @@ -2991,7 +2991,7 @@ private: _Locinfo::_Cvtvec _Cvt; // conversion information }; -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template <> class _CRTIMP2_PURE_IMPORT ctype : public ctype_base { // facet for classifying unsigned short elements, converting cases @@ -3197,7 +3197,7 @@ private: _Locinfo::_Ctypevec _Ctype; // locale info passed to _Tolower, etc. _Locinfo::_Cvtvec _Cvt; // conversion information }; -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) template class ctype_byname : public ctype<_Elem> { // ctype for named locale diff --git a/stl/inc/xstring b/stl/inc/xstring index cf09cc5c782..4d8b8f2f210 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -340,6 +340,11 @@ using u32streampos = streampos; template <> struct char_traits : _WChar_traits {}; +#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +template <> +struct char_traits : _WChar_traits {}; +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) + #if defined(__cpp_char8_t) && !defined(__EDG__) && !defined(__clang__) #define _HAS_U8_INTRINSICS 1 #else // ^^^ Use intrinsics for char8_t / don't use said intrinsics vvv From 66d84681316b7f36998e26f68c83cc7d4d641890 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 28 Aug 2021 21:43:52 +0700 Subject: [PATCH 4/9] restore stl/inc/xlocale again :( --- stl/inc/xlocale | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/stl/inc/xlocale b/stl/inc/xlocale index be1bb5936d2..29d93f06890 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -200,10 +200,10 @@ public: static void __CLRCALL_OR_CDECL _Makewloc( const _Locinfo&, category, _Locimp*, const locale*); // make wchar_t facets -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _NATIVE_WCHAR_T_DEFINED static void __CLRCALL_OR_CDECL _Makeushloc( const _Locinfo&, category, _Locimp*, const locale*); // make ushort facets -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _NATIVE_WCHAR_T_DEFINED static void __CLRCALL_OR_CDECL _Makexloc( const _Locinfo&, category, _Locimp*, const locale*); // make remaining facets @@ -472,7 +472,7 @@ inline char __CRTDECL _Maklocbyte(wchar_t _Char, const _Locinfo::_Cvtvec& _Cvt) return _Byte; } -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _NATIVE_WCHAR_T_DEFINED template <> inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Cvt) { // convert unsigned short to char using _Cvtvec @@ -481,7 +481,7 @@ inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Wcrtomb(&_Byte, static_cast(_Char), &_Mbst1, &_Cvt); return _Byte; } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _NATIVE_WCHAR_T_DEFINED template _Elem __CRTDECL _Maklocchr(char _Byte, _Elem*, const _Locinfo::_Cvtvec&) { @@ -498,7 +498,7 @@ inline wchar_t __CRTDECL _Maklocchr(char _Byte, wchar_t*, const _Locinfo::_Cvtve return _Wc; } -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _NATIVE_WCHAR_T_DEFINED template <> inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { // convert char to unsigned short using _Cvtvec @@ -507,7 +507,7 @@ inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _L _Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst1, &_Cvt); return _Wc; } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _NATIVE_WCHAR_T_DEFINED template _Elem* __CRTDECL _Maklocstr(const char* _Ptr, _Elem*, const _Locinfo::_Cvtvec&) { @@ -567,7 +567,7 @@ inline wchar_t* __CRTDECL _Maklocstr(const char* _Ptr, wchar_t*, const _Locinfo: return _Ptrdest; } -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _NATIVE_WCHAR_T_DEFINED template <> inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { // convert C string to unsigned short sequence using _Cvtvec @@ -605,7 +605,7 @@ inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, c *_Ptrnext = L'\0'; return reinterpret_cast(_Ptrdest); } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _NATIVE_WCHAR_T_DEFINED class _CRTIMP2_PURE_IMPORT codecvt_base : public locale::facet { // base class for codecvt public: @@ -2103,7 +2103,7 @@ private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _NATIVE_WCHAR_T_DEFINED template <> class _CRTIMP2_PURE_IMPORT codecvt : public codecvt_base { // facet for converting between unsigned short and char sequences @@ -2303,7 +2303,7 @@ protected: private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _NATIVE_WCHAR_T_DEFINED template class codecvt_byname : public codecvt<_Elem, _Byte, _Statype> { // codecvt for named locale @@ -2991,7 +2991,7 @@ private: _Locinfo::_Cvtvec _Cvt; // conversion information }; -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _NATIVE_WCHAR_T_DEFINED template <> class _CRTIMP2_PURE_IMPORT ctype : public ctype_base { // facet for classifying unsigned short elements, converting cases @@ -3197,7 +3197,7 @@ private: _Locinfo::_Ctypevec _Ctype; // locale info passed to _Tolower, etc. _Locinfo::_Cvtvec _Cvt; // conversion information }; -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _NATIVE_WCHAR_T_DEFINED template class ctype_byname : public ctype<_Elem> { // ctype for named locale From 2abc5bd363bd84eb5946d838a63b6a68c0e7911b Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 4 Sep 2021 09:44:30 +0700 Subject: [PATCH 5/9] delete ushistream, ushostream, ushfilebuf from iosfwd --- stl/inc/iosfwd | 5 ----- stl/src/ushcerr.cpp | 8 ++++++++ stl/src/ushcin.cpp | 8 ++++++++ stl/src/ushclog.cpp | 8 ++++++++ stl/src/ushcout.cpp | 8 ++++++++ stl/src/ushiostr.cpp | 8 ++++++++ 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/stl/inc/iosfwd b/stl/inc/iosfwd index 25d9c4641b9..dd07725d3ad 100644 --- a/stl/inc/iosfwd +++ b/stl/inc/iosfwd @@ -251,11 +251,6 @@ using wsyncbuf = basic_syncbuf; using wosyncstream = basic_osyncstream; #endif // _HAS_CXX20 -#if defined(_CRTBLD) -using ushistream = basic_istream>; -using ushostream = basic_ostream>; -using ushfilebuf = basic_filebuf>; -#endif // defined(_CRTBLD) _STD_END #pragma pop_macro("new") diff --git a/stl/src/ushcerr.cpp b/stl/src/ushcerr.cpp index 2b576925614..b813d0d27ed 100644 --- a/stl/src/ushcerr.cpp +++ b/stl/src/ushcerr.cpp @@ -6,6 +6,14 @@ #ifdef _NATIVE_WCHAR_T_DEFINED #include +_STD_BEGIN + +using ushistream = basic_istream>; +using ushostream = basic_ostream>; +using ushfilebuf = basic_filebuf>; + +_STD_END + #ifndef wistream #define wistream ushistream #define wostream ushostream diff --git a/stl/src/ushcin.cpp b/stl/src/ushcin.cpp index 5af2eb01839..3323192726c 100644 --- a/stl/src/ushcin.cpp +++ b/stl/src/ushcin.cpp @@ -6,6 +6,14 @@ #ifdef _NATIVE_WCHAR_T_DEFINED #include +_STD_BEGIN + +using ushistream = basic_istream>; +using ushostream = basic_ostream>; +using ushfilebuf = basic_filebuf>; + +_STD_END + #ifndef wistream #define wistream ushistream #define wostream ushostream diff --git a/stl/src/ushclog.cpp b/stl/src/ushclog.cpp index 8e0a16c15de..08895621c9b 100644 --- a/stl/src/ushclog.cpp +++ b/stl/src/ushclog.cpp @@ -6,6 +6,14 @@ #ifdef _NATIVE_WCHAR_T_DEFINED #include +_STD_BEGIN + +using ushistream = basic_istream>; +using ushostream = basic_ostream>; +using ushfilebuf = basic_filebuf>; + +_STD_END + #ifndef wistream #define wistream ushistream #define wostream ushostream diff --git a/stl/src/ushcout.cpp b/stl/src/ushcout.cpp index 2f81fae7b2b..30e1b45fcab 100644 --- a/stl/src/ushcout.cpp +++ b/stl/src/ushcout.cpp @@ -6,6 +6,14 @@ #ifdef _NATIVE_WCHAR_T_DEFINED #include +_STD_BEGIN + +using ushistream = basic_istream>; +using ushostream = basic_ostream>; +using ushfilebuf = basic_filebuf>; + +_STD_END + #ifndef wistream #define wistream ushistream #define wostream ushostream diff --git a/stl/src/ushiostr.cpp b/stl/src/ushiostr.cpp index 072766538a3..ea77e565309 100644 --- a/stl/src/ushiostr.cpp +++ b/stl/src/ushiostr.cpp @@ -6,6 +6,14 @@ #ifdef _NATIVE_WCHAR_T_DEFINED #include +_STD_BEGIN + +using ushistream = basic_istream>; +using ushostream = basic_ostream>; +using ushfilebuf = basic_filebuf>; + +_STD_END + #define wistream ushistream #define wostream ushostream #define wfilebuf ushfilebuf From f4b449e04dae69928ecc1388079dd1ae3012ca27 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 4 Sep 2021 09:59:42 +0700 Subject: [PATCH 6/9] `codecvt` needs to be visible only when `_ENFORCE_FACET_SPECIALIZATIONS` is 0 --- stl/inc/xlocale | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/stl/inc/xlocale b/stl/inc/xlocale index 29d93f06890..8774113180d 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -200,10 +200,10 @@ public: static void __CLRCALL_OR_CDECL _Makewloc( const _Locinfo&, category, _Locimp*, const locale*); // make wchar_t facets -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS static void __CLRCALL_OR_CDECL _Makeushloc( const _Locinfo&, category, _Locimp*, const locale*); // make ushort facets -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS static void __CLRCALL_OR_CDECL _Makexloc( const _Locinfo&, category, _Locimp*, const locale*); // make remaining facets @@ -472,7 +472,7 @@ inline char __CRTDECL _Maklocbyte(wchar_t _Char, const _Locinfo::_Cvtvec& _Cvt) return _Byte; } -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template <> inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Cvt) { // convert unsigned short to char using _Cvtvec @@ -481,7 +481,7 @@ inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec& _Wcrtomb(&_Byte, static_cast(_Char), &_Mbst1, &_Cvt); return _Byte; } -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template _Elem __CRTDECL _Maklocchr(char _Byte, _Elem*, const _Locinfo::_Cvtvec&) { @@ -498,7 +498,7 @@ inline wchar_t __CRTDECL _Maklocchr(char _Byte, wchar_t*, const _Locinfo::_Cvtve return _Wc; } -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template <> inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { // convert char to unsigned short using _Cvtvec @@ -507,7 +507,7 @@ inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _L _Mbrtowc(reinterpret_cast(&_Wc), &_Byte, 1, &_Mbst1, &_Cvt); return _Wc; } -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template _Elem* __CRTDECL _Maklocstr(const char* _Ptr, _Elem*, const _Locinfo::_Cvtvec&) { @@ -567,7 +567,7 @@ inline wchar_t* __CRTDECL _Maklocstr(const char* _Ptr, wchar_t*, const _Locinfo: return _Ptrdest; } -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template <> inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, const _Locinfo::_Cvtvec& _Cvt) { // convert C string to unsigned short sequence using _Cvtvec @@ -605,7 +605,7 @@ inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, c *_Ptrnext = L'\0'; return reinterpret_cast(_Ptrdest); } -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS class _CRTIMP2_PURE_IMPORT codecvt_base : public locale::facet { // base class for codecvt public: @@ -2103,7 +2103,7 @@ private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template <> class _CRTIMP2_PURE_IMPORT codecvt : public codecvt_base { // facet for converting between unsigned short and char sequences @@ -2303,7 +2303,7 @@ protected: private: _Locinfo::_Cvtvec _Cvt; // locale info passed to _Mbrtowc, _Wcrtomb }; -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template class codecvt_byname : public codecvt<_Elem, _Byte, _Statype> { // codecvt for named locale @@ -2991,7 +2991,7 @@ private: _Locinfo::_Cvtvec _Cvt; // conversion information }; -#ifdef _NATIVE_WCHAR_T_DEFINED +#if defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template <> class _CRTIMP2_PURE_IMPORT ctype : public ctype_base { // facet for classifying unsigned short elements, converting cases @@ -3197,7 +3197,7 @@ private: _Locinfo::_Ctypevec _Ctype; // locale info passed to _Tolower, etc. _Locinfo::_Cvtvec _Cvt; // conversion information }; -#endif // _NATIVE_WCHAR_T_DEFINED +#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS template class ctype_byname : public ctype<_Elem> { // ctype for named locale From 6e54ab2f3e2bb9d28fea602f9357e14587a35059 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sat, 4 Sep 2021 10:34:11 +0700 Subject: [PATCH 7/9] define _ENFORCE_FACET_SPECIALIZATIONS to 0 --- tests/std/tests/VSO_0397980_codecvt_length/test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/std/tests/VSO_0397980_codecvt_length/test.cpp b/tests/std/tests/VSO_0397980_codecvt_length/test.cpp index f18b6197ac2..e1d23def999 100644 --- a/tests/std/tests/VSO_0397980_codecvt_length/test.cpp +++ b/tests/std/tests/VSO_0397980_codecvt_length/test.cpp @@ -4,6 +4,9 @@ #define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING #define _SILENCE_CXX20_CODECVT_FACETS_DEPRECATION_WARNING +#undef _ENFORCE_FACET_SPECIALIZATIONS +#define _ENFORCE_FACET_SPECIALIZATIONS 0 + #include #include #include From 4af010a5a9ffdbc3b941f6bb4480bdffe968e01b Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 9 Jun 2022 14:29:19 +0700 Subject: [PATCH 8/9] collaps `#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD)` to `#ifdef _CRTBLD` --- stl/inc/fstream | 44 ++++++++++++++++++++++---------------------- stl/inc/iosfwd | 4 ++-- stl/inc/xstring | 4 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/stl/inc/fstream b/stl/inc/fstream index 86b22528f20..d8454a7f1bf 100644 --- a/stl/inc/fstream +++ b/stl/inc/fstream @@ -63,9 +63,9 @@ _INLINE_VAR constexpr bool _Is_any_path = _Is_any_of_v<_Ty _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int); _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int); -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const unsigned short*, ios_base::openmode, int); -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD template bool _Fgetc(_Elem& _Ch, FILE* _File) { // get an element from a C stream @@ -94,7 +94,7 @@ inline bool _Fgetc(wchar_t& _Wchar, FILE* _File) { // get a wchar_t element from } } -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD template <> inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) { // get an unsigned short element from a C stream wint_t _Meta; @@ -105,7 +105,7 @@ inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) { // get an unsigned sho return true; } } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD template bool _Fputc(_Elem _Ch, FILE* _File) { // put an element to a C stream @@ -122,12 +122,12 @@ inline bool _Fputc(wchar_t _Wchar, FILE* _File) { // put a wchar_t element to a return _CSTD fputwc(_Wchar, _File) != WEOF; } -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD template <> inline bool _Fputc(unsigned short _Wchar, FILE* _File) { // put an unsigned short element to a C stream return _CSTD fputwc(_Wchar, _File) != WEOF; } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD template bool _Ungetc(const _Elem&, FILE*) { // put back an arbitrary element to a C stream (always fail) @@ -154,12 +154,12 @@ inline bool _Ungetc(const wchar_t& _Wchar, FILE* _File) { // put back a wchar_t return _CSTD ungetwc(_Wchar, _File) != WEOF; } -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD template <> inline bool _Ungetc(const unsigned short& _Wchar, FILE* _File) { // put back an unsigned short element to a C stream return _CSTD ungetwc(_Wchar, _File) != WEOF; } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD template class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer associated with a C stream @@ -353,7 +353,7 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD basic_filebuf* open( const unsigned short* _Filename, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) { // in standard as const std::filesystem::path::value_type *; _Prot is an extension @@ -377,7 +377,7 @@ public: return open(_Filename, static_cast(_Mode)); } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD basic_filebuf* close() { basic_filebuf* _Ans; @@ -842,7 +842,7 @@ public: const _Ty& _Path, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) : basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD explicit basic_ifstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) : _Mybase(_STD addressof(_Filebuffer)) { @@ -851,7 +851,7 @@ public: _Myios::setstate(ios_base::failbit); } } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension @@ -921,7 +921,7 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) { // in standard as const std::filesystem::path::value_type *; _Prot is an extension @@ -938,7 +938,7 @@ public: open(_Filename, static_cast(_Mode)); } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD __CLR_OR_THIS_CALL ~basic_ifstream() noexcept override {} @@ -1025,7 +1025,7 @@ public: const _Ty& _Path, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) : basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD explicit basic_ofstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) : _Mybase(_STD addressof(_Filebuffer)) { @@ -1034,7 +1034,7 @@ public: _Myios::setstate(ios_base::failbit); } } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension @@ -1104,7 +1104,7 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) { // in standard as const std::filesystem::path::value_type *; _Prot is an extension @@ -1121,7 +1121,7 @@ public: open(_Filename, static_cast(_Mode)); } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD __CLR_OR_THIS_CALL ~basic_ofstream() noexcept override {} @@ -1213,7 +1213,7 @@ public: int _Prot = ios_base::_Default_open_prot) : basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD explicit basic_fstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out, int _Prot = ios_base::_Default_open_prot) : _Mybase(_STD addressof(_Filebuffer)) { @@ -1222,7 +1222,7 @@ public: _Myios::setstate(ios_base::failbit); } } -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension @@ -1293,7 +1293,7 @@ public: } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out, int _Prot = ios_base::_Default_open_prot) { // in standard as const std::filesystem::path::value_type *; _Prot is an extension @@ -1310,7 +1310,7 @@ public: open(_Filename, static_cast(_Mode)); } #endif // _HAS_OLD_IOSTREAMS_MEMBERS -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD __CLR_OR_THIS_CALL ~basic_fstream() noexcept override {} diff --git a/stl/inc/iosfwd b/stl/inc/iosfwd index e072c412203..2462b10426c 100644 --- a/stl/inc/iosfwd +++ b/stl/inc/iosfwd @@ -160,10 +160,10 @@ template <> struct char_traits; template <> struct char_traits; -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD template <> struct char_traits; -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD template class allocator; diff --git a/stl/inc/xstring b/stl/inc/xstring index 207155fc2e2..395ec12aec4 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -341,10 +341,10 @@ struct char_traits : _Char_traits {}; template <> struct char_traits : _WChar_traits {}; -#if defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#ifdef _CRTBLD template <> struct char_traits : _WChar_traits {}; -#endif // defined(_NATIVE_WCHAR_T_DEFINED) && defined(_CRTBLD) +#endif // _CRTBLD #if defined(__cpp_char8_t) && !defined(__EDG__) && !defined(__clang__) #define _HAS_U8_INTRINSICS 1 From 30774690e8e7e27fc382c16985eaaea79914183f Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 9 Jun 2022 14:45:12 +0700 Subject: [PATCH 9/9] remove `unsigned short` from `asserts` --- stl/inc/locale | 3 +-- stl/inc/xlocmes | 3 +-- stl/inc/xlocmon | 9 +++------ stl/inc/xlocnum | 9 +++------ stl/inc/xloctime | 6 ++---- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/stl/inc/locale b/stl/inc/locale index 483c3027a1c..c05ad267239 100644 --- a/stl/inc/locale +++ b/stl/inc/locale @@ -26,8 +26,7 @@ _STD_BEGIN template class collate : public locale::facet { // facet for ordering sequences of elements public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using char_type = _Elem; using string_type = basic_string<_Elem, char_traits<_Elem>, allocator<_Elem>>; diff --git a/stl/inc/xlocmes b/stl/inc/xlocmes index bab3b359750..b18070fa086 100644 --- a/stl/inc/xlocmes +++ b/stl/inc/xlocmes @@ -27,8 +27,7 @@ struct messages_base : locale::facet { // base class for messages template class messages : public messages_base { // facet for obtaining messages from a catalog public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using char_type = _Elem; using string_type = basic_string<_Elem, char_traits<_Elem>, allocator<_Elem>>; diff --git a/stl/inc/xlocmon b/stl/inc/xlocmon index 440bbbb1825..008cf5ee12b 100644 --- a/stl/inc/xlocmon +++ b/stl/inc/xlocmon @@ -244,8 +244,7 @@ private: template class moneypunct : public _Mpunct<_Elem> { // facet for defining monetary punctuation text public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); _PGLOBAL _CRTIMP2_PURE_IMPORT static const bool intl; // true if international __PURE_APPDOMAIN_GLOBAL _CRTIMP2_PURE_IMPORT static locale::id id; // unique facet id @@ -307,8 +306,7 @@ private: using _Mypunct1 = moneypunct<_Elem, true>; public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using char_type = _Elem; using iter_type = _InIt; @@ -612,8 +610,7 @@ private: using _Mypunct1 = moneypunct<_Elem, true>; public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using char_type = _Elem; using iter_type = _OutIt; diff --git a/stl/inc/xlocnum b/stl/inc/xlocnum index 5e272e75a8f..2b919f04ff8 100644 --- a/stl/inc/xlocnum +++ b/stl/inc/xlocnum @@ -98,8 +98,7 @@ private: friend _Tidy_guard; public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using string_type = basic_string<_Elem, char_traits<_Elem>, allocator<_Elem>>; using char_type = _Elem; @@ -259,8 +258,7 @@ __PURE_APPDOMAIN_GLOBAL locale::id numpunct<_Elem>::id; template >> class num_get : public locale::facet { // facet for converting text to encoded numbers public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet** _Ppf = nullptr, const locale* _Ploc = nullptr) { // return locale category mask and construct standard facet @@ -1166,8 +1164,7 @@ int _Float_put_desired_precision(const streamsize _Precision, const ios_base::fm template >> class num_put : public locale::facet { // facet for converting encoded numbers to text public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet** _Ppf = nullptr, const locale* _Ploc = nullptr) { // return locale category mask and construct standard facet diff --git a/stl/inc/xloctime b/stl/inc/xloctime index da4f55a9ae5..06652fd4c3a 100644 --- a/stl/inc/xloctime +++ b/stl/inc/xloctime @@ -106,8 +106,7 @@ private: friend _Tidy_guard; public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using char_type = _Elem; using iter_type = _InIt; @@ -649,8 +648,7 @@ protected: template >> class time_put : public locale::facet { // facet for converting encoded times to text public: - static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t, unsigned short>, - _FACET_SPECIALIZATION_MESSAGE); + static_assert(!_ENFORCE_FACET_SPECIALIZATIONS || _Is_any_of_v<_Elem, char, wchar_t>, _FACET_SPECIALIZATION_MESSAGE); using char_type = _Elem; using iter_type = _OutIt;