[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 --- Comment #17 from Jonathan Wakely --- Author: redi Date: Fri May 3 19:13:31 2019 New Revision: 270858 URL: https://gcc.gnu.org/viewcvs?rev=270858=gcc=rev Log: Avoid -Woverflow warning in __numeric_limits_integer This is the same fix as was done for std::numeric_limits in r183905. PR libstdc++/52119 * include/ext/numeric_traits.h (__glibcxx_min): Avoid integer overflow warning with -Wpedantic -Wsystem-headers. Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/ext/numeric_traits.h
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 --- Comment #16 from Jonathan Wakely --- Fixed by r225998 PR c++/55095 * c-common.c (c_fully_fold_internal): Warn about left shift overflows. Use EXPR_LOC_OR_LOC. (maybe_warn_shift_overflow): New function. * c-common.h (maybe_warn_shift_overflow): Declare. * c-opts.c (c_common_post_options): Set warn_shift_overflow. * c.opt (Wshift-overflow): New option. * c-typeck.c (digest_init): Pass OPT_Wpedantic to pedwarn_init. (build_binary_op): Warn about left shift overflows. * typeck.c (cp_build_binary_op): Warn about left shift overflows. * doc/invoke.texi: Document -Wshift-overflow and -Wshift-overflow=.
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 Martin Sebor changed: What|Removed |Added Status|NEW |RESOLVED CC||msebor at gcc dot gnu.org Resolution|--- |FIXED --- Comment #15 from Martin Sebor --- Recent versions of G++ diagnose shifting into the sign bit (and reject it in constexpr contexts) so this looks resolved: warning: result of ‘(2 << 31)’ requires 34 bits to represent, but ‘int’ only has 32 bits [-Wshift-overflow=] int n = 2 << 31; ~~^
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 ajf alan.j.flavell at gmail dot com changed: What|Removed |Added CC||alan.j.flavell at gmail dot com --- Comment #10 from ajf alan.j.flavell at gmail dot com --- (In reply to Jeffrey Yasskin from comment #0) numeric_limitsT::min() is defined as (__glibcxx_signed (T) ? (T)1 __glibcxx_digits (T) : (T)0). Unfortunately, shifting into the sign bit is undefined behavior (C++11[expr.shift]p2), and undefined behavior makes an expression non-constant. MY apologies if I am missing something obvious, but what exactly makes shifting a 1 into the sign bit undefined behavior? Seems rather defined to me, assuming it's actually being using as a integral numerical data-type (in this case, 32-bit int, long), which would result in a signed numerical value.In other words, the sign bit, like any other bit, can only be 0 or 1, so I honestly do not understand how undefined behavior enters the equation, or what impact it may have.
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 --- Comment #11 from Jason Merrill jason at gcc dot gnu.org --- (In reply to ajf from comment #10) MY apologies if I am missing something obvious, but what exactly makes shifting a 1 into the sign bit undefined behavior? You're right, it isn't: 5.8/2: ... if E1 has a signed type and non-negative value, and E1 × 2^E2 is representable in the corresponding unsigned type of the result type, then that value, converted to the result type, is the resulting value
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 --- Comment #12 from Jeffrey Yasskin jyasskin at gcc dot gnu.org --- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3675.html#1457 changed this between C++11 and C++14.
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 --- Comment #13 from Jason Merrill jason at gcc dot gnu.org --- (In reply to Jeffrey Yasskin from comment #12) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3675.html#1457 changed this between C++11 and C++14. True, but the defect report applies to C++11.
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 --- Comment #14 from Jeffrey Yasskin jyasskin at gcc dot gnu.org --- Whoops, I missed your comment 7 where you already knew the history. Sorry.
[Bug c++/52119] [C++11] overflow in signed left shift isn't diagnosed
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52119 Jason Merrill jason at gcc dot gnu.org changed: What|Removed |Added Status|RESOLVED|NEW Resolution|INVALID | Summary|numeric_limits::min() is|[C++11] overflow in signed |not a constant expression |left shift isn't diagnosed --- Comment #9 from Jason Merrill jason at gcc dot gnu.org 2012-02-14 00:38:14 UTC --- Good point.