> A colleague of mine reprodured the same failure as me on his x86_64
> architecture. I point this because I think this is the source of my issues.
> Does your architecture 64 bits?
>
> In fact, the message "Cannot convert data." comes from the template
> function string_to_integer into the file src/backends/postgresql/common.h
> Indeed, at the point the value of  static_cast<long long>(max)  is -1.
> I guess this is is because of the -Wno-long-long compilation option  (that
> is unfortunately no straightforward to remove).

in fact, this is not a problem of compilation option. It seems it directly 
comes to the template function I previously identified ( template function 
string_to_integer into the file src/backends/postgresql/common.h  - see below). 
Indeed, on my x86_64 architecture (but it may be different on another I guess) 
the "unsigned long" type and "long long" type are both 8 bytes. Thus the code:
        const T max = (std::numeric_limits<T>::max)();
        static_cast<long long>(max)

With T=unsigned long, it results into a value of -1 for the max value of the 
(signed) long long, resulting into the identified error since the tested value 
t is not into the target range (see below).

Moreover, this template function was not in soci 2.2, what would explain why 
my problems appeared with the 3.0 version.

However, I must admit I don't know yet what is the best solution to solve it 
properly and make the code portable to any 64 bit architecture. Any feedback 
and proposition are welcome.

Regards

HLB

-----------------------------------
template <typename T>
T string_to_integer(char const * buf)
{
    long long t;
    int n;
    int const converted = sscanf(buf, "%lld%n", &t, &n);
    if (converted == 1 && static_cast<std::size_t>(n) == strlen(buf))
    {
        // successfully converted to long long
        // and no other characters were found in the buffer

        const T max = (std::numeric_limits<T>::max)();
        const T min = (std::numeric_limits<T>::min)();
        if (t <= static_cast<long long>(max) &&
            t >= static_cast<long long>(min))
        {
            return static_cast<T>(t);
        }
        else
        {
            // value of out target range
            throw soci_error("string_to_integer (1) Cannot convert data.");
        }
    }
    else
    { ...


------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to