forked from boostorg/conversion
Fix #1791 (fix warning on MSVC warning level 4) and undo r34801 (some "rewording" to avoid spurious level 4 warnings with VC7.1 and VC8).
[SVN r56158]
This commit is contained in:
@@ -47,6 +47,13 @@
|
|||||||
#define BOOST_LCAST_NO_WCHAR_T
|
#define BOOST_LCAST_NO_WCHAR_T
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOOST_NO_TYPEID
|
||||||
|
#define BOOST_LCAST_THROW_BAD_CAST(S, T) throw_exception(bad_lexical_cast())
|
||||||
|
#else
|
||||||
|
#define BOOST_LCAST_THROW_BAD_CAST(Source, Target) \
|
||||||
|
throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)))
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
// exception used to indicate runtime lexical_cast failure
|
// exception used to indicate runtime lexical_cast failure
|
||||||
@@ -1111,6 +1118,12 @@ namespace boost
|
|||||||
typedef const T * type;
|
typedef const T * type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if (defined _MSC_VER)
|
||||||
|
# pragma warning( push )
|
||||||
|
# pragma warning( disable : 4701 ) // possible use of ... before initialization
|
||||||
|
# pragma warning( disable : 4702 ) // unreachable code
|
||||||
|
#endif
|
||||||
|
|
||||||
template< typename Target
|
template< typename Target
|
||||||
, typename Source
|
, typename Source
|
||||||
, bool Unlimited // string representation of Source is unlimited
|
, bool Unlimited // string representation of Source is unlimited
|
||||||
@@ -1136,28 +1149,14 @@ namespace boost
|
|||||||
, detail::lexical_stream_limited_src<CharT,base,traits>
|
, detail::lexical_stream_limited_src<CharT,base,traits>
|
||||||
>::type interpreter(buf, buf + src_len);
|
>::type interpreter(buf, buf + src_len);
|
||||||
|
|
||||||
// The original form, reproduced below, is more elegant
|
Target result;
|
||||||
// but yields a spurious C4701 warning ("possible use of
|
if(!(interpreter << arg && interpreter >> result))
|
||||||
// "result" before initialization") with VC7.1 (/W4).
|
BOOST_LCAST_THROW_BAD_CAST(Source, Target);
|
||||||
//
|
return result;
|
||||||
// Target result;
|
|
||||||
//
|
|
||||||
// if(!(interpreter << arg && interpreter >> result))
|
|
||||||
// throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)));
|
|
||||||
// return result;
|
|
||||||
|
|
||||||
if(interpreter << arg) {
|
|
||||||
Target result;
|
|
||||||
if (interpreter >> result)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#ifndef BOOST_NO_TYPEID
|
|
||||||
throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)));
|
|
||||||
#else
|
|
||||||
throw_exception(bad_lexical_cast());
|
|
||||||
#endif
|
|
||||||
return Target(); // normally never reached (throw_exception)
|
|
||||||
}
|
}
|
||||||
|
#if (defined _MSC_VER)
|
||||||
|
# pragma warning( pop )
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Target, typename Source>
|
template<typename Target, typename Source>
|
||||||
|
Reference in New Issue
Block a user