[Bug c++/93967] New: switch on exhaustive enum gives control reaches end of non-void function
gcc at cookiesoft dot de
gcc-bugzilla@gcc.gnu.org
Fri Feb 28 14:37:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93967
Bug ID: 93967
Summary: switch on exhaustive enum gives control reaches end of
non-void function
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++ input.cpp`
```
<source>: In function 'int foo(A)':
<source>:9:1: warning: control reaches end of non-void function [-Wreturn-type]
9 | }
| ^
```
The switch is exhaustive and so there is no way that the function reaches the
code path after the switch. Clang does not emit a warning.
This happens on every version of gcc.
Godbolt: https://cpp.godbolt.org/z/Goii_K
More information about the Gcc-bugs
mailing list