[webkit-dev] Heads up: FALLTHROUGH annotations for switches with fallthroughs

Brady Eidson beidson at apple.com
Sun Jan 26 10:23:49 PST 2014


I like this!

Out of curiosity, will it be needed for cases like:

switch (input) {
case 1:  // fallthrough?
case 2:
    // Handle both 1 and 2
    break;
default:
    // default
}

Thanks,
~Brady

On Jan 26, 2014, at 1:41 AM, Joseph Pecoraro <pecoraro at apple.com> wrote:

> Hello!
> 
> I'm slowly enabling -Wimplicit-fallthrough on projects in the Mac / iOS ports.
> <http://trac.webkit.org/changeset/162793>
> <http://clang.llvm.org/docs/LanguageExtensions.html#the-clang-fallthrough-attribute>
> 
> This means that if you write any switch statements with implicit fallthroughs it will produce build errors in projects with the warning enabled.
> 
> If you're writing a switch with a fallthrough, use the "FALLTHROUGH;" annotation (which expands to [[clang::fallthrough]];) to appease the warning.
> 
> The intent of this warning is to catch at compile time any accidental switch fallthroughs, and therefore explicitly annotate everywhere a fallthrough was intended.
> 
> Thanks,
> - JoePeck
> 
> --
> 
> For example. Here is a switch with an implicit fallthrough but no compiler recognized annotation:
> 
> switch (input) {
> case 1:
>     output -= 5;
>     // fallthrough
> default:
>     output += 5;
> }
> 
> When the warning is enabled you will see a build error like:
> 
> main.cpp:9:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
>     default:
>     ^
> main.cpp:9:5: note: insert 'FALLTHROUGH;' to silence this warning
>     default:
>     ^
>     FALLTHROUGH; 
> main.cpp:9:5: note: insert 'break;' to avoid fall-through
>     default:
>     ^
>     break; 
> 
> Use "FALLTHROUGH;" to annotate the fallthrough and build without errors:
> 
> switch (input) {
> case 1:
>     output -= 5;
>     FALLTHROUGH;
> default:
>     output += 5;
> }
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20140126/034f161a/attachment.html>


More information about the webkit-dev mailing list