A bug in boost.lexical_cast 1.30
When lexical_cast used under VC, and the option "Treat wchar_t as Build-in Type" is off The following code will cause compile error: int main(int argc, char * argv[]) { string str("10"); unsigned short n = lexical_cast<unsigned short>(str); return 0; } Because in lexical_cast::detail::widest_char, treat unsigned short as wchar_t!! -- /*******************/ ×ÔÓÉ£šliberty£©ÎÞ·ÇŸÍÊÇÕâÑùÒ»ÖÖ³Ðŵ£ºÃ¿žöÈËœ«»áµÃµœÒ»ÖÖ±£ÕÏ£¬±£ÕÏÎÒÃÇ¿ÉÒÔÓë ÈšÍþ¡¢¶àÊý¡¢Á÷Ë׌°ÓßÂÛµÄÓ°ÏìÏ࿹ºâ¡£ /*******************/
From: "Black Ice"
When lexical_cast used under VC, and the option "Treat wchar_t as Build-in Type" is off The following code will cause compile error: int main(int argc, char * argv[]) { string str("10"); unsigned short n = lexical_cast<unsigned short>(str); return 0; }
Because in lexical_cast::detail::widest_char, treat unsigned short as wchar_t!!
I have tested it, and can confirm this problem. The problem is that lexical_cast doesn't disable wide character support in this case. It seems it needs to test for BOOST_NO_INTRINSIC_WCHAR_T, after all, as it did earlier. In other words, change this: #if defined(BOOST_NO_STRINGSTREAM) || \ defined(BOOST_NO_STD_WSTRING) || \ defined(BOOST_NO_STD_LOCALE) || \ defined(BOOST_NO_CWCHAR) || \ defined(BOOST_MSVC) && (BOOST_MSVC <= 1200) #define DISABLE_WIDE_CHAR_SUPPORT #endif to this: #if defined(BOOST_NO_STRINGSTREAM) || \ defined(BOOST_NO_STD_WSTRING) || \ defined(BOOST_NO_STD_LOCALE) || \ defined(BOOST_NO_INTRINSIC_WCHAR_T) #define DISABLE_WIDE_CHAR_SUPPORT #endif and remove this: #ifdef BOOST_NO_INTRINSIC_WCHAR_T #include <cwchar> #endif If this is done, it works, both for the option on or off. This also disables wide character support on Intel C++, even though it handles it, as it doesn't set _NATIVE_WCHAR_T_DEFINED, even when intrinsic wchar_t is turned on. However, this is really an issue in the detection on Intel C++, rather than with lexical_cast. Regards, Terje
Thanks
--
/*******************/
×ÔÓÉ£šliberty£©ÎÞ·ÇŸÍÊÇÕâÑùÒ»ÖÖ³Ðŵ£ºÃ¿žöÈËœ«»áµÃµœÒ»ÖÖ±£ÕÏ£¬±£ÕÏÎÒÃÇ¿ÉÒÔÓë
ÈšÍþ¡¢¶àÊý¡¢Á÷Ë׌°ÓßÂÛµÄÓ°ÏìÏ࿹ºâ¡£
/*******************/
"Terje Sletteb?"
From: "Black Ice"
When lexical_cast used under VC, and the option "Treat wchar_t as Build-in Type" is off The following code will cause compile error: int main(int argc, char * argv[]) { string str("10"); unsigned short n = lexical_cast<unsigned short>(str); return 0; }
Because in lexical_cast::detail::widest_char, treat unsigned short as wchar_t!!
I have tested it, and can confirm this problem. The problem is that lexical_cast doesn't disable wide character support in this case. It seems it needs to test for BOOST_NO_INTRINSIC_WCHAR_T, after all, as it did earlier. In other words, change this:
#if defined(BOOST_NO_STRINGSTREAM) || \ defined(BOOST_NO_STD_WSTRING) || \ defined(BOOST_NO_STD_LOCALE) || \ defined(BOOST_NO_CWCHAR) || \ defined(BOOST_MSVC) && (BOOST_MSVC <= 1200) #define DISABLE_WIDE_CHAR_SUPPORT #endif
to this:
#if defined(BOOST_NO_STRINGSTREAM) || \ defined(BOOST_NO_STD_WSTRING) || \ defined(BOOST_NO_STD_LOCALE) || \ defined(BOOST_NO_INTRINSIC_WCHAR_T) #define DISABLE_WIDE_CHAR_SUPPORT #endif
and remove this:
#ifdef BOOST_NO_INTRINSIC_WCHAR_T #include <cwchar> #endif
If this is done, it works, both for the option on or off.
This also disables wide character support on Intel C++, even though it handles it, as it doesn't set _NATIVE_WCHAR_T_DEFINED, even when intrinsic wchar_t is turned on. However, this is really an issue in the detection on Intel C++, rather than with lexical_cast.
Regards,
Terje
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
participants (2)
-
Black Ice
-
Terje Slettebø