diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gcc~13/statement-attributes.html | |
new repository
Diffstat (limited to 'devdocs/gcc~13/statement-attributes.html')
| -rw-r--r-- | devdocs/gcc~13/statement-attributes.html | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/devdocs/gcc~13/statement-attributes.html b/devdocs/gcc~13/statement-attributes.html new file mode 100644 index 00000000..bf5ef5a8 --- /dev/null +++ b/devdocs/gcc~13/statement-attributes.html @@ -0,0 +1,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> |
