Subject: Re: [boost] Current Guidance on Compiler Warnings?
From: Gavin Lambert (boost_at_[hidden])
Date: 2018-11-26 04:52:26
On 26/11/2018 15:50, Emil Dotchevski wrote:
>> auto xu = std::make_unsigned_t<decltype(x)>(x);
>> if (xu < f())
>> This expresses your intent of using the unsigned version of the parameter.
> You probably mean
> auto xu = std::make_unsigned<decltype(x)>::type(x);
No, I meant what I wrote.
> This is similar to the implicit conversion, except it doesn't eliminate the
> other implicit conversion which will occur if the return type of f is of
> size greater than the size of x, which will likely earn you another
That was intentional, because that's another decision that has to be
made explicitly, with evaluation of the range constraints on f()'s
> Therefore you probably want
> auto xu = std::make_unsigned<decltype(f())>::type(x);
No, that's pointless. f() is already known to return an unsigned type
or you wouldn't have received the original warning in the first place.
You could use decltype(f()) by itself, but that doesn't really help
unless you know that it is always wider then x anyway.
> Fine. Do you think programmers actually write this to silence such
> warnings, rather than cast? Are you arguing that they should?
I don't think many currently do this, no. I wonder if they should,
given your complaint, but it's probably more generally useful to
encourage use of safe_numerics or similar instead.
> Ironically, in my experience the warning police doesn't care about the
> assert, even though it will actually catch the bugs they're trying to
> defend against, while the warning, silenced with a cast, won't.
True. The assert is more explicit and more useful (if actually
checked), but people seem unreasonably afraid of adding them for some
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk