public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/103826] New: Bogus shift-negative-value warning in C++20 mode @ 2021-12-25 10:26 manx-bugzilla at problemloesungsmaschine dot de 2021-12-25 10:53 ` [Bug c++/103826] " pinskia at gcc dot gnu.org 2021-12-25 11:23 ` manx-bugzilla at problemloesungsmaschine dot de 0 siblings, 2 replies; 3+ messages in thread From: manx-bugzilla at problemloesungsmaschine dot de @ 2021-12-25 10:26 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103826 Bug ID: 103826 Summary: Bogus shift-negative-value warning in C++20 mode Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: manx-bugzilla at problemloesungsmaschine dot de Target Milestone: --- C++20 changed the semantics when shifting negative values from undefined behavior to defined semantics. However, GCC still warns with -std=c++20 in this case, which is unfortunate, because it generates a lot of warnings when porting code to modern C++20. The warning is enabled by -Wextra. ``` int foo() { return (-32767) << 3; } ``` `-std=c++20 -Wall -Wextra -Wpedantic`: ``` <source>: In function 'int foo()': <source>:2:21: warning: left shift of negative value [-Wshift-negative-value] 2 | return (-32767) << 3; | ~~~~~~~~~^~~~ ``` Clang also warns in this case in C++17 mode, but does not warn in C++20 mode. See <https://godbolt.org/z/8Yd9qfveP>. ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/103826] Bogus shift-negative-value warning in C++20 mode 2021-12-25 10:26 [Bug c++/103826] New: Bogus shift-negative-value warning in C++20 mode manx-bugzilla at problemloesungsmaschine dot de @ 2021-12-25 10:53 ` pinskia at gcc dot gnu.org 2021-12-25 11:23 ` manx-bugzilla at problemloesungsmaschine dot de 1 sibling, 0 replies; 3+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-12-25 10:53 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103826 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2021-12-25 Ever confirmed|0 |1 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed, when the paper was implemented (r9-4132), this warning was missed it seems. Note I notice clang warns about: int main() { return (0x7000'0000) << 4; } Which is valid now too, GCC disabled the warning for C++20 with r9-4132. ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/103826] Bogus shift-negative-value warning in C++20 mode 2021-12-25 10:26 [Bug c++/103826] New: Bogus shift-negative-value warning in C++20 mode manx-bugzilla at problemloesungsmaschine dot de 2021-12-25 10:53 ` [Bug c++/103826] " pinskia at gcc dot gnu.org @ 2021-12-25 11:23 ` manx-bugzilla at problemloesungsmaschine dot de 1 sibling, 0 replies; 3+ messages in thread From: manx-bugzilla at problemloesungsmaschine dot de @ 2021-12-25 11:23 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103826 --- Comment #2 from Jörn Heusipp <manx-bugzilla at problemloesungsmaschine dot de> --- (In reply to Andrew Pinski from comment #1) > Note I notice clang warns about: > int main() { > return (0x7000'0000) << 4; > } It's valid, but clang complains here about shifting bits out of the range of the target type: warning: signed shift result (0x700000000) requires 36 bits to represent, but 'int' only has 32 bits [-Wshift-overflow] It does not warn when only shifting into the sign bit (and not overflowing the bits of the target type): return (0x7000'0000) << 1; I am not sure what the intended semantics of -Wshift-overflow is for clang, but I have reported <https://github.com/llvm/llvm-project/issues/52873>. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-12-25 11:23 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-12-25 10:26 [Bug c++/103826] New: Bogus shift-negative-value warning in C++20 mode manx-bugzilla at problemloesungsmaschine dot de 2021-12-25 10:53 ` [Bug c++/103826] " pinskia at gcc dot gnu.org 2021-12-25 11:23 ` manx-bugzilla at problemloesungsmaschine dot de
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).