Skip to content

Commit b9918bd

Browse files
JoePerchestorvalds
authored andcommitted
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: Joe Perches <[email protected]> Acked-by: Nick Desaulniers <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 294f69e commit b9918bd

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Documentation/process/coding-style.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ instead of ``double-indenting`` the ``case`` labels. E.g.:
5656
case 'K':
5757
case 'k':
5858
mem <<= 10;
59-
/* fall through */
59+
fallthrough;
6060
default:
6161
break;
6262
}

Documentation/process/deprecated.rst

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,27 @@ memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)
122122

123123
Implicit switch case fall-through
124124
---------------------------------
125-
The C language allows switch cases to "fall through" when
126-
a "break" statement is missing at the end of a case. This,
127-
however, introduces ambiguity in the code, as it's not always
128-
clear if the missing break is intentional or a bug. As there
129-
have been a long list of flaws `due to missing "break" statements
125+
The C language allows switch cases to "fall-through" when a "break" statement
126+
is missing at the end of a case. This, however, introduces ambiguity in the
127+
code, as it's not always clear if the missing break is intentional or a bug.
128+
129+
As there have been a long list of flaws `due to missing "break" statements
130130
<https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow
131-
"implicit fall-through". In order to identify an intentional fall-through
132-
case, we have adopted the marking used by static analyzers: a comment
133-
saying `/* Fall through */`. Once the C++17 `__attribute__((fallthrough))`
134-
is more widely handled by C compilers, static analyzers, and IDEs, we can
135-
switch to using that instead.
131+
"implicit fall-through".
132+
133+
In order to identify intentional fall-through cases, we have adopted a
134+
pseudo-keyword macro 'fallthrough' which expands to gcc's extension
135+
__attribute__((__fallthrough__)). `Statement Attributes
136+
<https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html>`_
137+
138+
When the C17/C18 [[fallthrough]] syntax is more commonly supported by
139+
C compilers, static analyzers, and IDEs, we can switch to using that syntax
140+
for the macro pseudo-keyword.
141+
142+
All switch/case blocks must end in one of:
143+
144+
break;
145+
fallthrough;
146+
continue;
147+
goto <label>;
148+
return [expression];

0 commit comments

Comments
 (0)