Fix regression in unsigned short to wstring casting without wchar_t b… (#92)

…uiltin type

Fixes: https://github.com/boostorg/lexical_cast/issues/89
This commit is contained in:
Antony Polukhin
2025-10-16 09:15:33 +03:00
committed by GitHub
parent 1084d98719
commit 275844e651
2 changed files with 16 additions and 1 deletions

View File

@@ -293,10 +293,12 @@ namespace boost { namespace detail { namespace lcast {
bool stream_in(lcast::exact<char> x) { return shl_char(x.payload); }
bool stream_in(lcast::exact<unsigned char> x) { return shl_char(static_cast<char>(x.payload)); }
bool stream_in(lcast::exact<signed char> x) { return shl_char(static_cast<char>(x.payload)); }
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <class C>
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<C> x) { return shl_char(x.payload); }
#endif
template <class Type>
enable_if_compatible_char_t<Type>

View File

@@ -32,9 +32,22 @@ void test_typedefed_wchar_t_runtime()
test_typedefed_wchar_t(L'0');
}
void test_unsigned_short_to_wstring()
{
// Test case from https://github.com/boostorg/lexical_cast/issues/89
unsigned short number = 4550;
auto res1 = boost::lexical_cast<std::wstring>(number);
BOOST_TEST(res1 == L"4550");
auto res2 = boost::lexical_cast<std::string>(number);
BOOST_TEST_EQ(res2, "4550");
}
int main()
{
test_typedefed_wchar_t_runtime();
test_unsigned_short_to_wstring();
return boost::report_errors();
}