public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49510] bitshift warnings Date: Tue, 28 Sep 2021 09:23:55 +0000 [thread overview] Message-ID: <bug-49510-4-Px8TewA3bW@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-49510-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49510 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Target Milestone|--- |4.9.0 Resolution|--- |FIXED --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Hmm, I don't think we can provide this for compile time warnings. We do provide runtime error/warnings with -fsanitize=undefined /app/example.cpp:7:46: runtime error: shift exponent 32 is too large for 32-bit type 'unsigned int' /app/example.cpp:8:28: runtime error: shift exponent 32 is too large for 32-bit type 'int' /app/example.cpp:11:48: runtime error: shift exponent -1 is negative /app/example.cpp:12:30: runtime error: shift exponent -1 is negative If the shifter was that constant we do provide compile time warnings already (and have for ever, in 4.1.2 for sure): <source>: In function 'int main()': <source>:7:46: warning: right shift count >= width of type [-Wshift-count-overflow] 7 | std::cout<<"0xFFFFFFFF>>32 = "<<(0xFFFFFFFF>>32)<<std::endl; | ~~~~~~~~~~^~~~ <source>:8:28: warning: left shift count >= width of type [-Wshift-count-overflow] 8 | std::cout<<"1<<32 = "<<(1<<32)<<std::endl; | ~^~~~ <source>:11:48: warning: right shift count is negative [-Wshift-count-negative] 11 | std::cout<<"0xFFFFFFFF>>(-1) = "<<(0xFFFFFFFF>>-1)<<std::endl; | ~~~~~~~~~~^~~~ <source>:12:30: warning: left shift count is negative [-Wshift-count-negative] 12 | std::cout<<"1<<(-1) = "<<(1<<-1)<<std::endl; | ~^~~~ -fsanitize=undefined was added in GCC 4.9.0. I don't see how we can warn without knowing if the code will be executed.
prev parent reply other threads:[~2021-09-28 9:23 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-06-23 0:39 [Bug c++/49510] New: " claytongdavis at gmail dot com 2011-06-23 11:43 ` [Bug c++/49510] " rguenth at gcc dot gnu.org 2021-09-28 9:23 ` pinskia at gcc dot gnu.org [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-49510-4-Px8TewA3bW@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).