[cfe-commits] [PATCH] Implicit fall-through between switch labels

Alexander Kornienko alexfh at google.com
Mon Apr 16 08:17:26 PDT 2012


Hi all,

This patch adds diagnostic of unintentional control flow fall-through
between switch labels. It also provides a way to specifically mark a switch
label with a c++ 11 attribute [[fallthrough]] to specify an intentional
fall-through. This also serves as an example of C++ 11 statement
attributes, and builds upon my recent patch, which introduces support for
this language feature.

This diagnostic is can be turned on using -Wimplicit-fallthrough option
(off by-default). The patch contains a test case
(test/SemaCXX/switch-implicit-fallthrough.cpp).

Example:
compile this code with -c -std=c++11 -Wimplicit-fallthrough

*int f(int n) { int t = 0; switch (n) { case 1: t = n; case 2: t = 2 * n;
break; } return t; }*

Compiler will emit a similar warning:

test.cpp:6:3: warning: missing 'break' or 'return' statement; use
[[fallthrough]] attribute to silence this warning [-Wimplicit-fallthrough]
case 2: ^ [[fallthrough]]

Then add [[fallthrough]] before "case 2:" and recompile. Warning will
not be issued.

Please, review this patch.

Thanks!


-- 
Best regards,
Alexander Kornienko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120416/ee5e704f/attachment.html>


More information about the cfe-commits mailing list