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

            Bug ID: 93968
           Summary: -Wswitch-default on exhaustive enum class gives
                    warning
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at cookiesoft dot de
  Target Milestone: ---

```
enum class A { X, Y, Z };

int foo(A a) {
    switch (a) {
        case A::X: return 1;
        case A::Y: return 2;
        case A::Z: return 3;
    }
}
```

`g++ -Wswitch-default input.cpp`

```
<source>: In function 'int foo(A)':
<source>:4:12: warning: switch missing default case [-Wswitch-default]
    4 |     switch (a) {
      |            ^
```

The switch is exhaustive and so there should no warning for a default case, but
when compiling it with `-Wswitch-default` it does emit a warning. Clang does
not.

This happens on every version of gcc.

Godbolt: https://cpp.godbolt.org/z/Goii_K

Reply via email to