Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance Guidelines
From: Christopher Jefferson (chris_at_[hidden])
Date: 2009-11-17 11:25:23
On 17 Nov 2009, at 16:22, Paul A. Bristow wrote:
>> -----Original Message-----
>> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On
> Behalf Of
>> Mateusz Loskot
>> Sent: Tuesday, November 17, 2009 3:36 PM
>> To: boost_at_[hidden]
>> Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance
>> Gottlob Frege wrote:
>>> On Mon, Nov 16, 2009 at 4:08 PM, Patrick Horgan <phorgan1_at_[hidden]> wrote:
>>>> C4800 Might suggest that they use a bool valued expression in the first
>>>> place, i.e. instead of foo, foo!=0, or do a static cast to bool. This is
>>>> times indicative of real bugs, when people turn out to not be doing what
>>>> they thought they were doing. Apparently this is one of my favorite bugs
>>>> (by favorite I don't mean that I like it either!)
>>> C4800: int' : forcing value to bool 'true' or 'false'
>>> I'm a big fan of using !! to convert to bool:
>>> bool has_item()
>>> Foo * foo = find_item();
>>> return !!foo; // convert ptr to bool
>>> Is that too subtle for others? It wouldn't be too subtle if it became
>>> a common idiom. :-)
>> It looks like a quite recommended idiom (double-bang trick)
> Looks OK to me but anyone 'deprecating' this before I add it to the guidelines?
> Are we sure that all compilers can evaluate this as compile time - otherwise
> while debugging users might find it a pest?
While this is a a workaround that disables the warning, I personally find it almost unreadable, and wouldn't want to encourage it's usage. In my mind when I see a ! I think "not", and have to always apply extra brain power to realise there are 2, and what it means.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk