public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104205] New: Signed overflow in case label reports confusing warning with -Wpedantic
@ 2022-01-24 15:00 stephen.wassell at sophos dot com
  2022-01-24 17:23 ` [Bug c/104205] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: stephen.wassell at sophos dot com @ 2022-01-24 15:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104205

            Bug ID: 104205
           Summary: Signed overflow in case label reports confusing
                    warning with -Wpedantic
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stephen.wassell at sophos dot com
  Target Milestone: ---

When compiling the following code with "gcc -Wpedantic":

    int convert(int err)
    {
        switch (err)
        {
            case 1 << 31: // signed overflow - undefined behaviour
                return 0;
            default:
                return 1;
        }
    }

    int main()
    {
        return convert(1 << 31);
    }

It reports a confusingly worded warning since version 6. It should say
something about undefined behaviour instead. Should there also be a warning for
the other use of 1 << 31?

    <source>: In function 'convert':
    <source>:5:9: warning: case label is not an integer constant expression
[-Wpedantic]
    5 |         case 1 << 31:
      |         ^~~~

Seen on gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0 x64, and multiple versions on
Compiler Explorer.

https://godbolt.org/z/4Tr1qxaqv

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-24 22:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 15:00 [Bug c/104205] New: Signed overflow in case label reports confusing warning with -Wpedantic stephen.wassell at sophos dot com
2022-01-24 17:23 ` [Bug c/104205] " pinskia at gcc dot gnu.org
2022-01-24 17:28 ` pinskia at gcc dot gnu.org
2022-01-24 17:37 ` stephen.wassell at sophos dot com
2022-01-24 20:07 ` egallager at gcc dot gnu.org
2022-01-24 22:46 ` joseph at codesourcery dot com

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).