Commit b9918bdc authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

Documentation/process: Add fallthrough pseudo-keyword

Describe the fallthrough pseudo-keyword.

Convert the coding-style.rst example to the keyword style.
Add description and links to deprecated.rst.

Miguel Ojeda comments on the eventual [[fallthrough]] syntax:
 "Note that C17/C18 does not have [[fallthrough]].

  C++17 introduced it, as it is mentioned above. I would keep the
  __attribute__((fallthrough)) -> [[fallthrough]] change you did,
  though, since that is indeed the standard syntax (given the paragraph
  references C++17).

  I was told by Aaron Ballman (who is proposing them for C) that it is
  more or less likely that it becomes standardized in C2x. However, it
  is still not added to the draft (other attributes are already,
  though). See N2268 and N2269:

     http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2268.pdf (fallthrough)
     http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2269.pdf (attributes in general)"
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 294f69e6
...@@ -56,7 +56,7 @@ instead of ``double-indenting`` the ``case`` labels. E.g.: ...@@ -56,7 +56,7 @@ instead of ``double-indenting`` the ``case`` labels. E.g.:
case 'K': case 'K':
case 'k': case 'k':
mem <<= 10; mem <<= 10;
/* fall through */ fallthrough;
default: default:
break; break;
} }
......
...@@ -122,14 +122,27 @@ memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`) ...@@ -122,14 +122,27 @@ memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)
Implicit switch case fall-through Implicit switch case fall-through
--------------------------------- ---------------------------------
The C language allows switch cases to "fall through" when The C language allows switch cases to "fall-through" when a "break" statement
a "break" statement is missing at the end of a case. This, is missing at the end of a case. This, however, introduces ambiguity in the
however, introduces ambiguity in the code, as it's not always code, as it's not always clear if the missing break is intentional or a bug.
clear if the missing break is intentional or a bug. As there
have been a long list of flaws `due to missing "break" statements As there have been a long list of flaws `due to missing "break" statements
<https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow <https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow
"implicit fall-through". In order to identify an intentional fall-through "implicit fall-through".
case, we have adopted the marking used by static analyzers: a comment
saying `/* Fall through */`. Once the C++17 `__attribute__((fallthrough))` In order to identify intentional fall-through cases, we have adopted a
is more widely handled by C compilers, static analyzers, and IDEs, we can pseudo-keyword macro 'fallthrough' which expands to gcc's extension
switch to using that instead. __attribute__((__fallthrough__)). `Statement Attributes
<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
When the C17/C18 [[fallthrough]] syntax is more commonly supported by
C compilers, static analyzers, and IDEs, we can switch to using that syntax
for the macro pseudo-keyword.
All switch/case blocks must end in one of:
break;
fallthrough;
continue;
goto <label>;
return [expression];
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment