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

Caolán McNamara caolanm at redhat.com
Thu Aug 3 16:44:12 UTC 2017


On Sun, 2017-07-30 at 19:26 +0200, Lionel Elie Mamane wrote:
> Hi,
> 
> 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]
> 
> But that is not true; since all possible values are treated and
> return, it cannot fall through. How do I silence that spurious
> warning-turned-error?

Seems that the "unhandled enum" stuff is working ok while the "end of
non-void function" isn't working, so....

enum class t {a, b};

OUString f(t i) 
{
  OUString ret;
  switch(i)
  { 
    case t::a:
        ret = "it was an a";
    case t::b:
        ret = "it was a b";
  }
  return ret;
}

would not have the return warning, but removing the case t::b: will
give a (desirable) enumeration value ‘b’ not handled


More information about the LibreOffice mailing list