silencing warning "control reaches end of non-void function"

Lionel Elie Mamane lionel at
Sun Jul 30 17:53:21 UTC 2017

On Sun, Jul 30, 2017 at 07:26:02PM +0200, Lionel Elie Mamane wrote:

> Consider:

> enum t {a, b};
> OUString f(t i)
> {
>   switch(i)
>   {
>   case t::a;
>     return "it was an a";
>   case t::b;
>     return "it was a b";
>   }
> }

> gcc -Werror fails with
> error: control reaches end of non-void function [-Werror=return-type]

An Internet search
teaches me that it is legal to construct a value of an enum type that
is not among the enumerated values (when the number of enumerated
values is not a power of two). <sigh>

I added the fake return. I prefer not to put a default case in the
switch, so that the "switch is not exhaustive over enum" warning can
still appear.


More information about the LibreOffice mailing list