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

2.0 KiB

[dcl.attr.nouniqueaddr]

9 Declarations [dcl]

9.13 Attributes [dcl.attr]

9.13.11 No unique address attribute [dcl.attr.nouniqueaddr]

1

#

The attribute-token no_unique_address specifies that a non-static data member is a potentially-overlapping subobject ([intro.object]).

No attribute-argument-clause shall be present.

The attribute may appertain to a non-static data member other than a bit-field.

2

#

[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.

— end note]

Recommended practice: The value of a has-attribute-expression 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.

[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.

— end example]