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

            Bug ID: 90805
           Summary: Overflow in switch case is not detected
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

My gcc is 10.0.0, and the code is:

int f(int cmd)
{
 switch (cmd) {
 case 0x80180000U:
 return 1;
 }
 return 0;
}

gcc accepts the code, but clang can detect its overflow:

<source>:4:7: error: case value evaluates to 2149056512, which cannot be
narrowed to type 'int' [-Wc++11-narrowing]

 case 0x80180000U:

      ^

1 error generated.

Compiler returned: 1

Reply via email to