Open djallen89 opened 3 weeks ago
Thanks for raising the issue! In short, overflow can't happen so there is no UB.
In your suggestion,
s
cannot be larger than 127.std::size_t
is probably not the best type for s
from the beginning: it should be the type allowing the best codegen, whatever that is. If the choice of type doesn't really matter in that regard, then we could just choose s
to be DecimalExponentType
so there is no warning. Otherwise, static_cast
should be enough.DecimalExponentType
though. I will fix it.My apologies, I didn't do a more in depth analysis of the code before submitting the issue. Thanks for responding so quickly!
Oh, don't get me wrong. My point was that I will investigate further and come up with a better solution if any. Thanks again!
In
include/dragonbox/dragonbox.h
, in each of theremove_trailing_zeros_traits
structs, on lines 2974 and 3012, the statementexponent += s;
invokes a warning from gcc when-Wconversions
andWsign-conversion
are enabled.I think a reasonable fix is the following:
The suggestion would be better imo if
detail::stdr
had its own analogue ofstd::remove_reference
, so that decltype could be used properly on exponent.If
s
+exponent
is expected to be able to wrap, that invokes undefined behavior without the option-fwrapv
. If it is intended to wrap, a modification to the algorithm involving an unsigned exponent representation with memcpy's back and forth may be required.