From ae68a3eb895428cc564868c6c6a8e4e1b9464baa Mon Sep 17 00:00:00 2001 From: Michael Goulish Date: Thu, 10 Jan 2013 18:35:15 +0000 Subject: QPID-4531 : older GCC libs have error on negative-zero cast. This is a real fix, a replacement for r1431435, which was written by a crazy person. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1431548 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/types/Variant.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'qpid/cpp/src') diff --git a/qpid/cpp/src/qpid/types/Variant.cpp b/qpid/cpp/src/qpid/types/Variant.cpp index 139ddc7ab4..8c9837e765 100644 --- a/qpid/cpp/src/qpid/types/Variant.cpp +++ b/qpid/cpp/src/qpid/types/Variant.cpp @@ -110,22 +110,28 @@ class VariantImpl } value; std::string encoding;//optional encoding for variable length data - template T convertFromString() const + template T convertFromString() const { const std::string& s = *value.string; try { - T r = boost::lexical_cast(s); - //lexical_cast won't fail if string is a negative number and T is unsigned - //So check that and allow special case of negative zero - //else its a non-zero negative number so throw exception at end of function - if (std::numeric_limits::is_signed || s.find('-') != 0 || r == 0) { - return r; + // Extra shenanigans to work around negative zero + // conversion error in older GCC libs. + if ( s[0] != '-' ) { + return boost::lexical_cast(s); + } else { + T r = boost::lexical_cast(s.substr(1)); + if (std::numeric_limits::is_signed) { + return -r; + } else { + if (r==0) return 0; + } } } catch(const boost::bad_lexical_cast&) { } throw InvalidConversion(QPID_MSG("Cannot convert " << s)); } + }; -- cgit v1.2.1