Boost logo

Boost :

Subject: Re: [boost] Official warnings policy?
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2009-11-12 05:24:03


> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On
Behalf Of
> Steven Watanabe
> Sent: Wednesday, November 11, 2009 6:56 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Official warnings policy?
>
> AMDG
>
> Paul A. Bristow wrote:
> >> Looks like the warnings occur depending on the types used in the unit
tests.
> >> For example, the warning mentioned above comes from the test code:
> >>
> >> typedef variant< short, const char* > t_var2;
> >> typedef variant< unsigned short, const char*, t_var2 > t_var5;
> >> typedef variant< unsigned short, const char*, t_var5 > t_var6;
> >>
> >> t_var6 v6;
> >> v6 = 58;
> >>
> >> Which looks like a legitimate warning about converting an integer (58) to a
short.
> >
> > Since this is expected, could the test use a static_cast to the right type?
> >
> > v6 = static_cast< t_var6 >(58);
> >
> > Does this quiet the warning?
> >
> > Or must it be v6 = static_cast< unsigned short >(58); ?
> >
> > Either way this would document that casting/converting takes place?
> >
> > And perhaps users should do this too? The static_cast documents that the
author
> > has thought about this.
>
> I'd be careful about adding a static_cast, since it changes exactly
> what's being tested. Part of the behavior of a class is the way it handles
> implicit conversions. Even conversions that generate warnings sometimes
> need to be tested.

You are right, as ever. But in this case, is it my ignorance of C++ or is there
no way of specifying an (unsigned) short,

The test wanted to use v6 = 58US;

Or unsigned short int i = 58U; v6 = i; ?

Or would just v6 = 58U avoid the warning?

In the test, I suspect that v6 = static_cast< t_var6 >(58); was what was really
wanted (or some way of getting at the first template type from the variant that
is beyond my skills).

Paul

---
Paul A. Bristow
Prizet Farmhouse
Kendal, UK   LA8 8AB
+44 1539 561830, mobile +44 7714330204
pbristow_at_[hidden]

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