This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/60439] No warning for case overflow in switch statement.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]