Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2011-09-26 11:04:57


On 26 September 2011 09:40, Olaf van der Spek <ml_at_[hidden]> wrote:

> On Mon, Sep 26, 2011 at 3:47 PM, Christian Holmquist
> <c.holmquist_at_[hidden]> wrote:
> > On 26 September 2011 06:02, Olaf van der Spek <ml_at_[hidden]> wrote:
> >
> >> On Mon, Sep 26, 2011 at 8:30 AM, Christian Holmquist
> >> <c.holmquist_at_[hidden]> wrote:
> >> > Sometimes types unfortunately have implicit conversion, and if the
> >> compiler
> >> > finds them (I guess that what's common_type deduces?),I might end up
> with
> >> a
> >> > bogus expression that unfortunately compiles.
> >>
> >> Could you give a concrete example (with 3 type clamp)?
> >>
> >
> > enum A{a};
> > enum B(b);
> > main()
> > {
> > clamp(0, a, b);
> > }
> >
>
> Right.
> g++ 4.6: warning: enumeral mismatch in conditional expression: ‘A’ vs ‘B’
>

Ok, it's good that gcc warns about this. MSVC doesn't.

>
> Is this really the fault of clamp() though?
>
No, but clamp can avoid exposing this inherited problem, just as
std::min/std::max does.

The same 'mistake' can easily be made in normal code.
>
Yes, and it is causing trouble. We can't go back and change the rules for
implicit conversions between native types, but when there is a possibility
to get rid of the legacy I think one should opt to do so.

> Olaf
>
> Christian


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