Boost logo

Boost :

From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2004-11-22 16:54:56


On Mon, 22 Nov 2004 12:54:17 -0800
"Robert Ramey" <ramey_at_[hidden]> wrote:

> I've never really understood this warning - basically it reminds me
> that I did what I intended to do.

Are you always sure?

bool
basic_iarchive_impl::track(
    basic_iarchive & ar,
    void * & t
){
    object_id_type oid;
    load(ar, oid);

    // if its a reference to a old object
    if(object_id_type(object_id_vector.size()) > oid){
        // we're done
        t = object_id_vector[oid].address;
        return false;
    }
    return true;
}

object_id_vector is a std::vector<>, so it has...

reference operator[](size_type n), where size_type is "unsigned int"

The line that generates the warning wants to convert a "object_id_type"
to a "unsigned int" so it can pass the index to operator[]().

However, object_id_type is a class (BOOST_STRONG_DEF) with the following
conversion operators...

    operator T () const {return t; } \
    operator T & () { return t; } \

where T is "unsigned int"

So, in the attempt to convert from object_id_type to "unsigned int", we
try both of the operators, and they both match. So, the compiler can
not decide which one you want, because your object is non-const. Maybe
in this situation, it does not matter, but there are many situations in
which this multiple match can cause harm.

So, I think the warnings should be eliminated, to prevent a piece of
"bad" use from being overlooked because we get used to seeing these
warnings.

The presence of both operators in the BOOST_STRONG_DEF is what causes
this ambiguity...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk