Files
cppdraft_translate/cppdraft/dcl/attr/nouniqueaddr.md
2025-10-25 03:02:53 +03:00

46 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[dcl.attr.nouniqueaddr]
# 9 Declarations [[dcl]](./#dcl)
## 9.13 Attributes [[dcl.attr]](dcl.attr#nouniqueaddr)
### 9.13.11 No unique address attribute [dcl.attr.nouniqueaddr]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L10145)
The [*attribute-token*](dcl.attr.grammar#nt:attribute-token "9.13.1Attribute syntax and semantics[dcl.attr.grammar]") no_unique_address specifies that a non-static data member
is a potentially-overlapping subobject ([[intro.object]](intro.object "6.8.2Object model"))[.](#1.sentence-1)
No [*attribute-argument-clause*](dcl.attr.grammar#nt:attribute-argument-clause "9.13.1Attribute syntax and semantics[dcl.attr.grammar]") shall be present[.](#1.sentence-2)
The attribute may appertain to a non-static data member
other than a bit-field[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L10153)
[*Note [1](#note-1)*:
The non-static data member can share the address of
another non-static data member or that of a base class,
and any padding that would normally be inserted
at the end of the object
can be reused as storage for other members[.](#2.sentence-1)
— *end note*]
*Recommended practice*: The value of a [*has-attribute-expression*](cpp.cond#nt:has-attribute-expression "15.2Conditional inclusion[cpp.cond]") for the no_unique_address attribute
should be 0 for a given implementation
unless this attribute can cause a potentially-overlapping subobject
to have zero size[.](#2.sentence-2)
[*Example [1](#example-1)*: template<typename Key, typename Value, typename Hash, typename Pred, typename Allocator>class hash_map {[[no_unique_address]] Hash hasher; [[no_unique_address]] Pred pred; [[no_unique_address]] Allocator alloc;
Bucket *buckets; // ...public:// ...};
Here, hasher, pred, and alloc could have the same address as buckets if their respective types are all empty[.](#2.sentence-3)
— *end example*]