Boost logo

Boost :

Subject: Re: [boost] Official warnings policy?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-11-12 09:34:31


John Maddock wrote:
>
> Delving into this a bit deeper, I believe the warning is
> correct, and cannot / should not be fixed, to recap we have:
>
> d:\data\boost\trunk\boost/variant/variant.hpp(1297) : warning C4244:
> 'argument' : conversion from 'const int' to 'const short',
> possible loss of data
[snip template traceback]

> The code calls Variant's converting-assignment operator, and
> Boost.Variant internally decides what type to convert the
> argument to and makes the assignment. In this case the user
> *should* see a warning to be alerted to the fact that the
> internal conversion results in loss of precision (likewise they
> would see an error in this location if there is no suitable
> conversion).

Indeed, Variant shouldn't suppress the warning, but wasn't the
original issue because a test was triggering it? IOW, it is the
test code that should work around or suppress the warning.

> I notice that the code in question has a comment to this effect:
[snip possible reasons for compilation errors]
> But perhaps we should add a similar note about compiler warnings?

I don't think that's really necessary, but it might be useful:

// Warnings about loss of precision cannot be addressed here
// without adding runtime range checking overhead, so must be
// addressed in the calling code when they arise.

Perhaps it would be possible to add a checked_assign member
function that does a numeric_cast as part of the assignment to
deduce the target type and verify that the actual value being
assigned doesn't exceed the target type's range. Then, the
comment above could suggest using that function instead.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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