Date: prev next · Thread: first prev next last
2017 Archives by date, by thread · List index


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
https://stackoverflow.com/questions/33607284/control-reaches-end-of-non-void-function-with-fully-handled-case-switch-over-a
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.

-- 
Lionel

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.