Subject: Re: [boost] Current Guidance on Compiler Warnings?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2018-11-24 18:48:17


On Sat, Nov 24, 2018 at 7:53 AM Peter Dimov via Boost <boost_at_[hidden]>
wrote:
>
> Daniela Engert wrote:
> > Am 23.11.2018 um 20:58 schrieb Emil Dotchevski via Boost:
> > >
> > > unsigned f();
> > >
> > > void g( int x )
> > > {
> > > if( x < f() ) //warning C4018: '<': signed/unsigned mismatch
> > > {
> > > ....
> > > }
> > > }
> >
> > The only problem that I can see here is the fact, that this is flagged
as
> > a warning rather than an error. I know, this is technically correct but
> > you simply cannot compare values from different value domains without
> > preconditions.
>
> Making it an error would be a useful first step towards making it work
> correctly. :-)
>
> (It's perfectly possible to compare a value in [INT_MIN, INT_MAX] with a
> value in [0, UINT_MAX], it's just that the standard says op< needs to do
the
> wrong thing.)

The problem with signed/unsigned mismatch is not just in the comparison,
but also in the operations. If unsigned x=2, the expression x-3 may not be
meaningfully represented by an unsigned integer, and your proposed change
to op< semantics would still produce incorrect result.

I do not know if it is possible to solve this problem in all arithmetic
operations, but practically speaking it doesn't matter.