[PATCH] Fix overflow in __gnu_cxx::__numeric_traits::__min
Jonathan Wakely
jwakely@redhat.com
Fri Dec 1 15:09:00 GMT 2017
On 01/12/17 14:34 +0000, Jonathan Wakely wrote:
>On 01/12/17 15:22 +0100, Paolo Carlini wrote:
>>Hi,
>>
>>On 01/12/2017 15:11, Jonathan Wakely wrote:
>>>On 01/12/17 14:02 +0000, Jonathan Wakely wrote:
>>>>Is there a reason we left-shift into the sign bit, causing undefined
>>>>behaviour? The approach used in std::numeric_limits seems better.
>>>
>>>The current code warns with -Wpedantic -Wsystem-headers:
>>>
>>>/usr/include/c++/7/ext/numeric_traits.h:58:35: warning: overflow
>>>in implicit constant conversion [-Woverflow]
>>>Â Â Â Â Â static const _Value __min = __glibcxx_min(_Value);
>>>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ^~~~~~~~~~~~~
>>Many details can be found in c++/52119. Which should probably be
>>updated, right?
>>
>>At the time I handled the libstdc++ side of the issue, and for some
>>reason forgot to fix at the same time the ext/numeric_traits bits. I
>>have no idea why, maybe to be conservative, in a way.
>
>Huh, so is the warning wrong? Is it only undefined in C++98?
Oh I see, we actually get a different warning on trunk:
/home/jwakely/gcc/8/include/c++/8.0.0/ext/numeric_traits.h:58:55: warning: overflow in conversion from âintâ to âshort intâ changes value from â32768â to â-32768â [-Woverflow]
static const _Value __min = __glibcxx_min(_Value);
^
So we just need a cast instead.
More information about the Libstdc++
mailing list