blob: c1c06f6bfd749a3e763ac56b2b4c8bf21a070939 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<h1 id="firstHeading" class="firstHeading">C attribute: fallthrough <span class="t-mark-rev t-since-c23">(since C23)</span>
</h1> <p>Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.</p>
<h3 id="Syntax"> Syntax</h3> <table class="t-sdsc-begin"> <tr class="t-sdsc"> <td class="t-sdsc-nopad"> <code>[[</code> <code>fallthrough</code> <code>]]</code><br><code>[[</code> <code>__fallthrough__</code> <code>]]</code> </td> <td class="t-sdsc-nopad"> </td> <td class="t-sdsc-nopad"> </td>
</tr>
</table> <h3 id="Explanation"> Explanation</h3> <p>May only be used in an <a href="../declarations" title="c/language/declarations">attribute declaration</a> to create a <i>fallthrough declaration</i> (<code>[[fallthrough]];</code>).</p>
<p>A fallthrough declaration may only be used in a <a href="../switch" title="c/language/switch"><code>switch</code></a> statement, where the next block item (statement, declaration, or label) to be encounted is a statement with a <code>case</code> or <code>default</code> label for that switch statement.</p>
<p>Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdbool.h>
void g(void) {}
void h(void) {}
void i(void) {}
void f(int n) {
switch (n) {
case 1:
case 2:
g();
[[fallthrough]];
case 3: // no warning on fallthrough
h();
case 4: // compiler may warn on fallthrough
if(n < 3) {
i();
[[fallthrough]]; // OK
}
else {
return;
}
case 5:
while (false) {
[[fallthrough]]; // ill-formed: no subsequent case or default label
}
case 6:
[[fallthrough]]; // ill-formed: no subsequent case or default label
}
}
int main(void) {}</pre></div> </div> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/language/attributes/fallthrough" title="cpp/language/attributes/fallthrough">C++ documentation</a></span> for <code>fallthrough</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/language/attributes/fallthrough" class="_attribution-link">https://en.cppreference.com/w/c/language/attributes/fallthrough</a>
</p>
</div>
|