Skip to content

Commit

Permalink
When wchar_t is a real type, users shouldn't see unsigned short machi…
Browse files Browse the repository at this point in the history
…nery (#2164)
  • Loading branch information
fsb4000 authored Jun 16, 2022
1 parent 183a1e2 commit 85274ba
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 63 deletions.
44 changes: 22 additions & 22 deletions stl/inc/fstream
Original file line number Diff line number Diff line change
Expand Up @@ -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);

#ifdef _NATIVE_WCHAR_T_DEFINED
#ifdef _CRTBLD
_CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const unsigned short*, ios_base::openmode, int);
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

template <class _Elem>
bool _Fgetc(_Elem& _Ch, FILE* _File) { // get an element from a C stream
Expand Down Expand Up @@ -94,7 +94,7 @@ inline bool _Fgetc(wchar_t& _Wchar, FILE* _File) { // get a wchar_t element from
}
}

#ifdef _NATIVE_WCHAR_T_DEFINED
#ifdef _CRTBLD
template <>
inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) { // get an unsigned short element from a C stream
wint_t _Meta;
Expand All @@ -105,7 +105,7 @@ inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) { // get an unsigned sho
return true;
}
}
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

template <class _Elem>
bool _Fputc(_Elem _Ch, FILE* _File) { // put an element to a C stream
Expand All @@ -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;
}

#ifdef _NATIVE_WCHAR_T_DEFINED
#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 // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

template <class _Elem>
bool _Ungetc(const _Elem&, FILE*) { // put back an arbitrary element to a C stream (always fail)
Expand All @@ -154,12 +154,12 @@ 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
#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 // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

template <class _Elem, class _Traits>
class basic_filebuf : public basic_streambuf<_Elem, _Traits> { // stream buffer associated with a C stream
Expand Down Expand Up @@ -353,7 +353,7 @@ public:
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS

#ifdef _NATIVE_WCHAR_T_DEFINED
#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
Expand All @@ -377,7 +377,7 @@ public:
return open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

basic_filebuf* close() {
basic_filebuf* _Ans;
Expand Down Expand Up @@ -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

#ifdef _NATIVE_WCHAR_T_DEFINED
#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)) {
Expand All @@ -851,7 +851,7 @@ public:
_Myios::setstate(ios_base::failbit);
}
}
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension

Expand Down Expand Up @@ -921,7 +921,7 @@ public:
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS

#ifdef _NATIVE_WCHAR_T_DEFINED
#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
Expand All @@ -938,7 +938,7 @@ public:
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

__CLR_OR_THIS_CALL ~basic_ifstream() noexcept override {}

Expand Down Expand Up @@ -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

#ifdef _NATIVE_WCHAR_T_DEFINED
#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)) {
Expand All @@ -1034,7 +1034,7 @@ public:
_Myios::setstate(ios_base::failbit);
}
}
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension

Expand Down Expand Up @@ -1104,7 +1104,7 @@ public:
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS

#ifdef _NATIVE_WCHAR_T_DEFINED
#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
Expand All @@ -1121,7 +1121,7 @@ public:
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

__CLR_OR_THIS_CALL ~basic_ofstream() noexcept override {}

Expand Down Expand Up @@ -1213,7 +1213,7 @@ public:
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension

#ifdef _NATIVE_WCHAR_T_DEFINED
#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)) {
Expand All @@ -1222,7 +1222,7 @@ public:
_Myios::setstate(ios_base::failbit);
}
}
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {} // extension

Expand Down Expand Up @@ -1293,7 +1293,7 @@ public:
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS

#ifdef _NATIVE_WCHAR_T_DEFINED
#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
Expand All @@ -1310,7 +1310,7 @@ public:
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif // _HAS_OLD_IOSTREAMS_MEMBERS
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

__CLR_OR_THIS_CALL ~basic_fstream() noexcept override {}

Expand Down
9 changes: 2 additions & 7 deletions stl/inc/iosfwd
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ template <>
struct char_traits<char32_t>;
template <>
struct char_traits<wchar_t>;
#ifdef _NATIVE_WCHAR_T_DEFINED
#ifdef _CRTBLD
template <>
struct char_traits<unsigned short>;
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // _CRTBLD

template <class _Ty>
class allocator;
Expand Down Expand Up @@ -278,11 +278,6 @@ using wospanstream = basic_ospanstream<wchar_t>;
using wspanstream = basic_spanstream<wchar_t>;
#endif // _HAS_CXX23

#if defined(_CRTBLD)
using ushistream = basic_istream<unsigned short, char_traits<unsigned short>>;
using ushostream = basic_ostream<unsigned short, char_traits<unsigned short>>;
using ushfilebuf = basic_filebuf<unsigned short, char_traits<unsigned short>>;
#endif // defined(_CRTBLD)
_STD_END

#pragma pop_macro("new")
Expand Down
3 changes: 1 addition & 2 deletions stl/inc/locale
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ _STD_BEGIN
template <class _Elem>
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>>;
Expand Down
24 changes: 12 additions & 12 deletions stl/inc/xlocale
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -481,7 +481,7 @@ inline char __CRTDECL _Maklocbyte(unsigned short _Char, const _Locinfo::_Cvtvec&
_Wcrtomb(&_Byte, static_cast<wchar_t>(_Char), &_Mbst1, &_Cvt);
return _Byte;
}
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS

template <class _Elem>
_Elem __CRTDECL _Maklocchr(char _Byte, _Elem*, const _Locinfo::_Cvtvec&) {
Expand All @@ -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
Expand All @@ -507,7 +507,7 @@ inline unsigned short __CRTDECL _Maklocchr(char _Byte, unsigned short*, const _L
_Mbrtowc(reinterpret_cast<wchar_t*>(&_Wc), &_Byte, 1, &_Mbst1, &_Cvt);
return _Wc;
}
#endif // _NATIVE_WCHAR_T_DEFINED
#endif // defined(_NATIVE_WCHAR_T_DEFINED) && !_ENFORCE_FACET_SPECIALIZATIONS

template <class _Elem>
_Elem* __CRTDECL _Maklocstr(const char* _Ptr, _Elem*, const _Locinfo::_Cvtvec&) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -605,7 +605,7 @@ inline unsigned short* __CRTDECL _Maklocstr(const char* _Ptr, unsigned short*, c
*_Ptrnext = L'\0';
return reinterpret_cast<unsigned short*>(_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:
Expand Down Expand Up @@ -2117,7 +2117,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<unsigned short, char, mbstate_t> : public codecvt_base {
// facet for converting between unsigned short and char sequences
Expand Down Expand Up @@ -2317,7 +2317,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 _Elem, class _Byte, class _Statype>
class codecvt_byname : public codecvt<_Elem, _Byte, _Statype> { // codecvt for named locale
Expand Down Expand Up @@ -3005,7 +3005,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<unsigned short>
: public ctype_base { // facet for classifying unsigned short elements, converting cases
Expand Down Expand Up @@ -3211,7 +3211,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 _Elem>
class ctype_byname : public ctype<_Elem> { // ctype for named locale
Expand Down
3 changes: 1 addition & 2 deletions stl/inc/xlocmes
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ struct messages_base : locale::facet { // base class for messages
template <class _Elem>
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>>;
Expand Down
9 changes: 3 additions & 6 deletions stl/inc/xlocmon
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ private:
template <class _Elem, bool _Intl = false>
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ private:
friend _Tidy_guard<numpunct>;

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;
Expand Down Expand Up @@ -259,8 +258,7 @@ __PURE_APPDOMAIN_GLOBAL locale::id numpunct<_Elem>::id;
template <class _Elem, class _InIt = istreambuf_iterator<_Elem, char_traits<_Elem>>>
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
Expand Down Expand Up @@ -1166,8 +1164,7 @@ int _Float_put_desired_precision(const streamsize _Precision, const ios_base::fm
template <class _Elem, class _OutIt = ostreambuf_iterator<_Elem, char_traits<_Elem>>>
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
Expand Down
Loading

0 comments on commit 85274ba

Please sign in to comment.