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/c_002b_002b-attributes.html | |
new repository
Diffstat (limited to 'devdocs/gcc~13/c_002b_002b-attributes.html')
| -rw-r--r-- | devdocs/gcc~13/c_002b_002b-attributes.html | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/devdocs/gcc~13/c_002b_002b-attributes.html b/devdocs/gcc~13/c_002b_002b-attributes.html new file mode 100644 index 00000000..b842366d --- /dev/null +++ b/devdocs/gcc~13/c_002b_002b-attributes.html @@ -0,0 +1,15 @@ +<div class="section-level-extent" id="C_002b_002b-Attributes"> <div class="nav-panel"> <p> Next: <a href="function-multiversioning" accesskey="n" rel="next">Function Multiversioning</a>, Previous: <a href="bound-member-functions" accesskey="p" rel="prev">Extracting the Function Pointer from a Bound Pointer to Member Function</a>, Up: <a href="c_002b_002b-extensions" accesskey="u" rel="up">Extensions to the C++ Language</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="C_002b_002b-Specific-Variable_002c-Function_002c-and-Type-Attributes"><span>7.7 C++-Specific Variable, Function, and Type Attributes<a class="copiable-link" href="#C_002b_002b-Specific-Variable_002c-Function_002c-and-Type-Attributes"> ¶</a></span></h1> <p>Some attributes only make sense for C++ programs. </p> <dl class="table"> <dt> + <span><code class="code">abi_tag ("<var class="var">tag</var>", ...)</code><a class="copiable-link" href="#index-abi_005ftag-function-attribute"> ¶</a></span> +</dt> <dd> +<p>The <code class="code">abi_tag</code> attribute can be applied to a function, variable, or class declaration. It modifies the mangled name of the entity to incorporate the tag name, in order to distinguish the function or class from an earlier version with a different ABI; perhaps the class has changed size, or the function has a different return type that is not encoded in the mangled name. </p> <p>The attribute can also be applied to an inline namespace, but does not affect the mangled name of the namespace; in this case it is only used for <samp class="option">-Wabi-tag</samp> warnings and automatic tagging of functions and variables. Tagging inline namespaces is generally preferable to tagging individual declarations, but the latter is sometimes necessary, such as when only certain members of a class need to be tagged. </p> <p>The argument can be a list of strings of arbitrary length. The strings are sorted on output, so the order of the list is unimportant. </p> <p>A redeclaration of an entity must not add new ABI tags, since doing so would change the mangled name. </p> <p>The ABI tags apply to a name, so all instantiations and specializations of a template have the same tags. The attribute will be ignored if applied to an explicit specialization or instantiation. </p> <p>The <samp class="option">-Wabi-tag</samp> flag enables a warning about a class which does not have all the ABI tags used by its subobjects and virtual functions; for users with code that needs to coexist with an earlier ABI, using this option can help to find all affected types that need to be tagged. </p> <p>When a type involving an ABI tag is used as the type of a variable or return type of a function where that tag is not already present in the signature of the function, the tag is automatically applied to the variable or function. <samp class="option">-Wabi-tag</samp> also warns about this situation; this warning can be avoided by explicitly tagging the variable or function or moving it into a tagged inline namespace. </p> </dd> <dt> +<span><code class="code">init_priority (<var class="var">priority</var>)</code><a class="copiable-link" href="#index-init_005fpriority-variable-attribute"> ¶</a></span> +</dt> <dd> <p>In Standard C++, objects defined at namespace scope are guaranteed to be initialized in an order in strict accordance with that of their definitions <em class="emph">in a given translation unit</em>. No guarantee is made for initializations across translation units. However, GNU C++ allows users to control the order of initialization of objects defined at namespace scope with the <code class="code">init_priority</code> attribute by specifying a relative <var class="var">priority</var>, a constant integral expression currently bounded between 101 and 65535 inclusive. Lower numbers indicate a higher priority. </p> <p>In the following example, <code class="code">A</code> would normally be created before <code class="code">B</code>, but the <code class="code">init_priority</code> attribute reverses that order: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">Some_Class A __attribute__ ((init_priority (2000))); +Some_Class B __attribute__ ((init_priority (543)));</pre> +</div> <p>Note that the particular values of <var class="var">priority</var> do not matter; only their relative ordering. </p> </dd> <dt> +<span><code class="code">warn_unused</code><a class="copiable-link" href="#index-warn_005funused-type-attribute"> ¶</a></span> +</dt> <dd> <p>For C++ types with non-trivial constructors and/or destructors it is impossible for the compiler to determine whether a variable of this type is truly unused if it is not referenced. This type attribute informs the compiler that variables of this type should be warned about if they appear to be unused, just like variables of fundamental types. </p> <p>This attribute is appropriate for types which just represent a value, such as <code class="code">std::string</code>; it is not appropriate for types which control a resource, such as <code class="code">std::lock_guard</code>. </p> <p>This attribute is also accepted in C, but it is unnecessary because C does not have constructors or destructors. </p> </dd> </dl> </div> <div class="nav-panel"> <p> Next: <a href="function-multiversioning">Function Multiversioning</a>, Previous: <a href="bound-member-functions">Extracting the Function Pointer from a Bound Pointer to Member Function</a>, Up: <a href="c_002b_002b-extensions">Extensions to the C++ Language</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/C_002b_002b-Attributes.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/C_002b_002b-Attributes.html</a> + </p> +</div> |
