Skip to content

When wchar_t is a real type, users shouldn't see unsigned short machinery - #2164

Merged
Stephan T. Lavavej (StephanTLavavej) merged 14 commits into
microsoft:mainfrom
fsb4000:fix216
Jun 16, 2022
Merged

When wchar_t is a real type, users shouldn't see unsigned short machinery#2164
Stephan T. Lavavej (StephanTLavavej) merged 14 commits into
microsoft:mainfrom
fsb4000:fix216

Conversation

@fsb4000

Copy link
Copy Markdown
Contributor

Fixes #216

@fsb4000
Igor Zhukov (fsb4000) requested a review from a team as a code owner August 28, 2021 08:16
@fsb4000
Igor Zhukov (fsb4000) marked this pull request as draft August 28, 2021 09:39
@fsb4000

Copy link
Copy Markdown
Contributor Author

I'm not quite sure if I need to do something with codecvt <unsigned short, char, mbstate_t>, need I?
And to which file do I need to move:

STL/stl/inc/iosfwd

Lines 254 to 258 in 78ff461

#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)

?

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the enhancement Something can be improved label Aug 30, 2021
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm not quite sure if I need to do something with codecvt <unsigned short, char, mbstate_t>, need I?

I suspect (70% sure) that it should be guarded by #ifdef _CRTBLD instead of #ifdef _NATIVE_WCHAR_T_DEFINED. That way, it will still be exported, but users with native wchar_t won't see it.

STL/stl/inc/xlocale

Lines 2106 to 2108 in 3136525

#ifdef _NATIVE_WCHAR_T_DEFINED
template <>
class _CRTIMP2_PURE_IMPORT codecvt<unsigned short, char, mbstate_t> : public codecvt_base {

#endif // _NATIVE_WCHAR_T_DEFINED


And to which file do I need to move:

Only the 5 following source files mention ush* - I am 98% sure that these are the only files that need the typedefs.

STL/stl/src/ushcerr.cpp

Lines 10 to 12 in 3136525

#define wistream ushistream
#define wostream ushostream
#define wfilebuf ushfilebuf

STL/stl/src/ushcin.cpp

Lines 10 to 12 in 3136525

#define wistream ushistream
#define wostream ushostream
#define wfilebuf ushfilebuf

STL/stl/src/ushclog.cpp

Lines 10 to 12 in 3136525

#define wistream ushistream
#define wostream ushostream
#define wfilebuf ushfilebuf

STL/stl/src/ushcout.cpp

Lines 10 to 12 in 3136525

#define wistream ushistream
#define wostream ushostream
#define wfilebuf ushfilebuf

#define wistream ushistream
#define wostream ushostream
#define wfilebuf ushfilebuf

@CaseyCarter

Casey Carter (CaseyCarter) commented Aug 31, 2021

Copy link
Copy Markdown
Contributor

I'm not quite sure if I need to do something with codecvt <unsigned short, char, mbstate_t>, need I?

I suspect (70% sure) that it should be guarded by #ifdef _CRTBLD instead of #ifdef _NATIVE_WCHAR_T_DEFINED. That way, it will still be exported, but users with native wchar_t won't see it.

Summarizing here a discussion I had with myself in Discord: explicit template specializations should be visible whenever it's possible to instantiate them implicitly from a primary template or partial specialization. Hiding explicit specializations is simply asking for ODR violation nightmares. Consequently, I think codecvt <unsigned short, char, mbstate_t> needs to be visible only when _ENFORCE_FACET_SPECIALIZATIONS is 0 (which should be the case when _CRTBLD is defined).

@fsb4000
Igor Zhukov (fsb4000) marked this pull request as ready for review September 4, 2021 04:09
Comment thread stl/inc/fstream Outdated
Comment thread stl/inc/xlocale

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for helping to partially excise this historical abomination.

Comment thread stl/inc/fstream
_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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never given it any thought before, but seriously who put defined in the name of a macro so we have to query if MEOW_DEFINED is defined??!? This is even worse that putting not in the name of a boolean condition. (No change requested.)

Comment thread stl/src/ushcerr.cpp
_STD_END

#ifndef wistream
#define wistream ushistream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤮🤮🤮 (No change requested; looking in these old sources can be painful.)

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 85274ba into microsoft:main Jun 16, 2022
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks again for eliminating these bizarre specializations as much as possible! 👻 🎉 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STL: When wchar_t is a real type, users shouldn't see unsigned short machinery

4 participants