From a9697b88fd3b946d6e8a4a7f678d5b0f7533843d Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 8 Dec 2011 15:29:44 +0000 Subject: [PATCH] Fixes #6186 (lexical_cast compliation error fixed, when wchar_t is a typedef for unsigned short. Test added) [SVN r75864] --- include/boost/lexical_cast.hpp | 15 ++++++- test/Jamfile.v2 | 7 ++- test/lexical_cast_typedefed_wchar_test.cpp | 50 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100755 test/lexical_cast_typedefed_wchar_test.cpp diff --git a/include/boost/lexical_cast.hpp b/include/boost/lexical_cast.hpp index e7ab248..480d87a 100644 --- a/include/boost/lexical_cast.hpp +++ b/include/boost/lexical_cast.hpp @@ -1093,6 +1093,8 @@ namespace boost namespace detail // optimized stream wrapper { + struct type_used_as_workaround_for_typedefed_wchar_ts{}; + // String representation of Source has an upper limit. template< class CharT // a result of widest_char transformation , class Traits // usually char_traits @@ -1354,6 +1356,8 @@ namespace boost /************************************ HELPER FUNCTIONS FOR OPERATORS >> ( ... ) ********************************/ private: + bool shr_unsigned(type_used_as_workaround_for_typedefed_wchar_ts /*var*/) {return true;} + template bool shr_unsigned(Type& output) { @@ -1480,8 +1484,15 @@ namespace boost } /************************************ OPERATORS >> ( ... ) ********************************/ - public: - bool operator>>(unsigned short& output) { return shr_unsigned(output); } + + typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::if_c< + ::boost::is_same::value + , type_used_as_workaround_for_typedefed_wchar_ts + , unsigned short + >::type ushort_ambiguity_workaround; + + public: + bool operator>>(ushort_ambiguity_workaround& output){ return shr_unsigned(output); } bool operator>>(unsigned int& output) { return shr_unsigned(output); } bool operator>>(unsigned long int& output) { return shr_unsigned(output); } bool operator>>(short& output) { return shr_signed(output); } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6eebe72..e7408f3 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -14,7 +14,12 @@ # bring in rules for testing import testing ; +import feature ; +feature.feature nowchar : on : + composite optional propagated link-incompatible ; +feature.compose on : /Zc:wchar_t- ; + test-suite conversion : [ run implicit_cast.cpp ] [ compile-fail implicit_cast_fail.cpp ] @@ -30,6 +35,6 @@ test-suite conversion [ run lexical_cast_inf_nan_test.cpp ../../test/build//boost_unit_test_framework/static ] [ run lexical_cast_containers_test.cpp ../../test/build//boost_unit_test_framework/static ] [ run lexical_cast_empty_input_test.cpp ../../test/build//boost_unit_test_framework/static ] + [ run lexical_cast_typedefed_wchar_test.cpp ../../test/build//boost_unit_test_framework/static : : : msvc:on : : ] ; - diff --git a/test/lexical_cast_typedefed_wchar_test.cpp b/test/lexical_cast_typedefed_wchar_test.cpp new file mode 100755 index 0000000..ae84678 --- /dev/null +++ b/test/lexical_cast_typedefed_wchar_test.cpp @@ -0,0 +1,50 @@ +// Unit test for boost::lexical_cast. +// +// See http://www.boost.org for most recent version, including documentation. +// +// Copyright Antony Polukhin, 2011. +// +// Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). + +#include + +#if defined(__INTEL_COMPILER) +#pragma warning(disable: 193 383 488 981 1418 1419) +#elif defined(BOOST_MSVC) +#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800) +#endif + +#include +#include + +void test_typedefed_wchar_t(); + +using namespace boost; + +unit_test::test_suite *init_unit_test_suite(int, char *[]) +{ + unit_test::test_suite *suite = + BOOST_TEST_SUITE("lexical_cast unit test for typedefed wchar_t (mainly for MSVC)"); + suite->add(BOOST_TEST_CASE(&test_typedefed_wchar_t)); + + return suite; +} + + +void test_typedefed_wchar_t() +{ +#ifdef BOOST_MSVC + BOOST_CHECK((boost::is_same::value)); +#endif + + BOOST_CHECK_EQUAL(lexical_cast(L"1000"), 1000); +} + + + + + + +