Question about a warning message

Juan Cabrera jjcp.91@gmail.com
Thu Sep 6 17:58:00 GMT 2018


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.



More information about the Gcc-help mailing list