[webkit-dev] Idiom for functions with all return values in a switch case

Andy Estes aestes at apple.com
Tue May 9 11:33:29 PDT 2017



> On May 9, 2017, at 11:06 AM, Michael Catanzaro <mcatanzaro at igalia.com> wrote:
> 
> https://bugs.webkit.org/show_bug.cgi?id=171851 <https://bugs.webkit.org/show_bug.cgi?id=171851> suggests this approach:
> 
>       static WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
>       {
>           switch (event) {
>               // ...
>           }
> 
>           ASSERT_NOT_REACHED();
>           return 0;
>       }
> 
> That works for the cases in that bug, but it won't work in this case, because the return value here is an enum, so a cast would be needed.

You wouldn’t need a cast if you returned one of the enumeration values (say, the first one) instead of 0.

I prefer this option for the reason Maciej gave.

Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20170509/f766e542/attachment.html>


More information about the webkit-dev mailing list