Why is T[] trivially copyable but not trivially destructible?

Viewed 165

First of all, what is the correct term for T[] (not T[12] and not T*)?

Second, if T is both trivially copyable and trivially destructible, why is T[] trivially copyable but not trivially destructible? I know it is for bounded arrays (T[12]).

godbolt

1 Answers

First of all, what is the correct term for T[]

It is an array of unknown bound (shortened to AOUB below).


Why is T[] not trivially destructible?

Standard (latest draft):

[meta.unary.prop]

Trait: is_­trivially_­destructible

Condition: is_­destructible_­v is true and ...

Trait: is_­destructible

Condition: Either T is a reference type, or T is a complete object type for which ...

An AOUB is neither a reference type, nor is it a complete type. Thus it does not have the trait is_­destructible and thus it has is_trivially_destructible neither.


Why is T[] trivially copyable

Standard (latest draft):

[meta.unary.prop]

Trait: is_trivially_copyable

Condition: T is a trivially copyable type ([basic.types])

[basic.types.general]

Arithmetic types ..., arrays of such types, and ... are collectively called trivially copyable types.

Note that there is no exception for arrays of unknown bound. They are trivially copyable too according to this rule.

Related