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
|
<div class="section-level-extent" id="Statement-Attributes"> <div class="nav-panel"> <p> Next: <a href="attribute-syntax" accesskey="n" rel="next">Attribute Syntax</a>, Previous: <a href="enumerator-attributes" accesskey="p" rel="prev">Enumerator Attributes</a>, Up: <a href="c-extensions" accesskey="u" rel="up">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Statement-Attributes-1"><span>6.38 Statement Attributes<a class="copiable-link" href="#Statement-Attributes-1"> ¶</a></span></h1> <p>GCC allows attributes to be set on null statements. See <a class="xref" href="attribute-syntax">Attribute Syntax</a>, for details of the exact syntax for using attributes. Other attributes are available for functions (see <a class="pxref" href="function-attributes">Declaring Attributes of Functions</a>), variables (see <a class="pxref" href="variable-attributes">Specifying Attributes of Variables</a>), labels (see <a class="pxref" href="label-attributes">Label Attributes</a>), enumerators (see <a class="pxref" href="enumerator-attributes">Enumerator Attributes</a>), and for types (see <a class="pxref" href="type-attributes">Specifying Attributes of Types</a>). </p> <dl class="table"> <dt>
<span><code class="code">fallthrough</code><a class="copiable-link" href="#index-fallthrough-statement-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">fallthrough</code> attribute with a null statement serves as a fallthrough statement. It hints to the compiler that a statement that falls through to another case label, or user-defined label in a switch statement is intentional and thus the <samp class="option">-Wimplicit-fallthrough</samp> warning must not trigger. The fallthrough attribute may appear at most once in each attribute list, and may not be mixed with other attributes. It can only be used in a switch statement (the compiler will issue an error otherwise), after a preceding statement and before a logically succeeding case label, or user-defined label. </p> <p>This example uses the <code class="code">fallthrough</code> statement attribute to indicate that the <samp class="option">-Wimplicit-fallthrough</samp> warning should not be emitted: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">switch (cond)
{
case 1:
bar (1);
__attribute__((fallthrough));
case 2:
…
}</pre>
</div> </dd> <dt>
<span><code class="code">assume</code><a class="copiable-link" href="#index-assume-statement-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">assume</code> attribute with a null statement serves as portable assumption. It should have a single argument, a conditional expression, which is not evaluated. If the argument would evaluate to true at the point where it appears, it has no effect, otherwise there is undefined behavior. This is a GNU variant of the ISO C++23 standard <code class="code">assume</code> attribute, but it can be used in any version of both C and C++. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int
foo (int x, int y)
{
__attribute__((assume(x == 42)));
__attribute__((assume(++y == 43)));
return x + y;
}</pre>
</div> <p><code class="code">y</code> is not actually incremented and the compiler can but does not have to optimize it to just <code class="code">return 42 + 42;</code>. </p> </dd> </dl> </div> <div class="nav-panel"> <p> Next: <a href="attribute-syntax">Attribute Syntax</a>, Previous: <a href="enumerator-attributes">Enumerator Attributes</a>, Up: <a href="c-extensions">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
<p class="_attribution-p">
© Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Statement-Attributes.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Statement-Attributes.html</a>
</p>
</div>
|