This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/60439] No warning for case overflow in switch statement.
- From: "chengniansun at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 13 Mar 2014 18:39:03 +0000
- Subject: [Bug c/60439] No warning for case overflow in switch statement.
- Auto-submitted: auto-generated
- References: <bug-60439-4 at http dot gcc dot gnu dot 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.