public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "chengniansun at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/60439] No warning for case overflow in switch statement.
Date: Thu, 13 Mar 2014 18:39:00 -0000	[thread overview]
Message-ID: <bug-60439-4-izfmBd51VA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-60439-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60439

--- Comment #4 from Chengnian Sun <chengniansun at gmail dot com> ---
(In reply to Chengnian Sun from comment #3)
> (In reply to Marek Polacek from comment #2)
> > Right.  So I think there's nothing much to do.  Please reopen if you
> > strongly disagree.
> 
> Hi Marek, 
> 
> From the perspective of type system, I think no warning is fine. But from
> the viewpoint of practice, IMHO this should be an overlooked case, as at
> runtime there is indeed overflow. 
> 
> The reason that I filed this report is not only that Clang emits a warning
> on this issue (shown as below), but also that Gcc is able to handle the
> value range of expressions (if I under the report PR60036 correctly).
> 
> ------------------------------------------------------------------- 
> 
> $: clang-trunk -Wswitch s.c  -c
> s.c:3:8: warning: overflow converting case value to switch condition type
> (111111 to 7) [-Wswitch]
>   case 111111: return 1; /*warning here*/
>        ^
> s.c:8:3: warning: switch condition has boolean value
>   switch(c && d) {
>   ^      ~~~~~~

Correction. There should be no overflow, but the case 1111 will never be
touched, right? In this case, I still think it is better to alert developers.


  parent reply	other threads:[~2014-03-13 18:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06  7:06 [Bug c/60439] New: " chengniansun at gmail dot com
2014-03-13 14:37 ` [Bug c/60439] " mpolacek at gcc dot gnu.org
2014-03-13 18:34 ` chengniansun at gmail dot com
2014-03-13 18:39 ` chengniansun at gmail dot com [this message]
2014-03-13 18:45 ` mpolacek at gcc dot gnu.org
2014-03-13 18:49 ` chengniansun at gmail dot com
2014-04-17 18:47 ` mpolacek at gcc dot gnu.org
2014-06-03 17:36 ` mpolacek at gcc dot gnu.org
2014-06-03 17:38 ` mpolacek at gcc dot gnu.org
2014-06-11 17:23 ` gary at intrepid dot com
2014-06-11 17:45 ` mpolacek at gcc dot gnu.org
2014-06-11 17:53 ` gary at intrepid dot com
2014-06-16 12:38 ` mpolacek at gcc dot gnu.org

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-60439-4-izfmBd51VA@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: link
Be 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).