gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-commit] [SCM] Gnash branch, objecturi, updated. a3e2d11b545fc


From: Benjamin Wolsey
Subject: Re: [Gnash-commit] [SCM] Gnash branch, objecturi, updated. a3e2d11b545fcdb326df4229e9524bf27d4fc9bd
Date: Thu, 23 Sep 2010 09:38:33 +0200

> > 
> > Ouch, this introduced a weird bug: 'this' is not found (in swf7+)
> 
> So, this was the equals() function defined _before_ the
> equality operator used in it.
> 
> Compiler was syntetizing another equality operator based on the
> "safe" (how much safe!) bool operator...

If you introduce a conversion to bool, there will always be an equality
comparison!

You can prevent it by defining operator!() instead of conversion to
bool, but that restricts the way you can use the class to if(!uri), but
not if (uri).

The properly safe bool idiom:

struct ObjectURI
{
private:
    typedef void(ObjectURI::*Safe)() const;
    void non_comparable() const {};
public:
    operator Safe() const {
        return true ? &ObjectURI::non_comparable : 0;
    }

};

prevents automatic less-than comparison, which operator const void*
doesn't, but it still allows equality comparison!

I see the branch has

operator<(const ObjectURI&, const ObjectURI&);

defined, but I suspect anyone using operator>() instead would currently
get the bogus comparison of const void*s.

bwy

--
Free Flash, use Gnash
http://www.gnu.org/software/gnash/

Benjamin Wolsey, Software Developer - http://benjaminwolsey.de
C++ and Open-Source Flash blog - http://www.benjaminwolsey.de/bwysblog

xmpp:address@hidden
http://identi.ca/bwy

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]