This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Question about a warning message
- From: Juan Cabrera <jjcp dot 91 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 6 Sep 2018 14:58:24 -0300
- Subject: Question about a warning message
Hello,
I'm getting a "control reaches end of non-void function" warning
message on the following code (tested with gcc version 7.3 and above):
enum class T { A, B };
int f(T t) {
switch (t) {
case T::A: return 10;
case T::B: return 20;
}
}
https://godbolt.org/z/IXC4Ff
Shouldn't the compiler assume that function `f` always returns
something for all valid inputs `t`? (Given that the parameter `t` is
of type `T` which is an enum class and the siwtch statement covers all
the enum values).
Regards,
Juan.