You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mg...@apache.org on 2013/01/10 19:35:15 UTC
svn commit: r1431548 - /qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp
Author: mgoulish
Date: Thu Jan 10 18:35:15 2013
New Revision: 1431548
URL: http://svn.apache.org/viewvc?rev=1431548&view=rev
Log:
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.
Modified:
qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp
Modified: qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp?rev=1431548&r1=1431547&r2=1431548&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/types/Variant.cpp Thu Jan 10 18:35:15 2013
@@ -110,22 +110,28 @@ class VariantImpl
} value;
std::string encoding;//optional encoding for variable length data
- template<class T> T convertFromString() const
+ template<class T> T convertFromString() const
{
const std::string& s = *value.string;
try {
- T r = boost::lexical_cast<T>(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<T>::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<T>(s);
+ } else {
+ T r = boost::lexical_cast<T>(s.substr(1));
+ if (std::numeric_limits<T>::is_signed) {
+ return -r;
+ } else {
+ if (r==0) return 0;
+ }
}
} catch(const boost::bad_lexical_cast&) {
}
throw InvalidConversion(QPID_MSG("Cannot convert " << s));
}
+
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org