Whether copying an object of the given type involves either a user-defined
copy / postblit constructor or a compiler-generated copy / postblit
constructor rather than using the default copying behavior (which would use
memcpy).
The compiler will generate a copy / postblit constructor for a struct when
a member variable of that struct defines a copy / postblit constructor.
Note that hasComplexCopying is also true for static arrays whose
element type has a copy constructor or postblit constructor, since while
the static array itself does not have a copy constructor or postblit
constructor, the compiler must use the copy / postblit constructor of the
elements when copying the static array.
Due to https://issues.dlang.org/show_bug.cgi?id=24833, enums never have complex copying even if their
base type does. Their copy / postblit constructor is never called,
resulting in incorrect behavior for such enums. So, because the compiler
does not treat them as having complex copying, hasComplexCopying is
false for them.
No other types (including class references, pointers, and unions) ever have
a copy constructor or postblit constructor and thus hasComplexCopying is
never true for them. It is particularly important to note that unions
never have a copy constructor or postblit constructor, so if a struct
contains a union which contains one or more members which have a copy
constructor or postblit constructor, that struct will have to have a
user-defined copy constructor or posthblit constructor which explicitly
copies the correct member of the union if you don't want the current value
of the union to simply be memcopied when copying the struct.
If a particular piece of code cares about the existence of a copy
constructor or postblit constructor specifically rather than if a type has
one or the other, the traits
__traits(hasCopyConstructor, T)
and
__traits(hasPostblit, T) can
be used, though note that they will not be true for static arrays.
Whether copying an object of the given type involves either a user-defined copy / postblit constructor or a compiler-generated copy / postblit constructor rather than using the default copying behavior (which would use memcpy).
The compiler will generate a copy / postblit constructor for a struct when a member variable of that struct defines a copy / postblit constructor.
Note that hasComplexCopying is also true for static arrays whose element type has a copy constructor or postblit constructor, since while the static array itself does not have a copy constructor or postblit constructor, the compiler must use the copy / postblit constructor of the elements when copying the static array.
Due to https://issues.dlang.org/show_bug.cgi?id=24833, enums never have complex copying even if their base type does. Their copy / postblit constructor is never called, resulting in incorrect behavior for such enums. So, because the compiler does not treat them as having complex copying, hasComplexCopying is false for them.
No other types (including class references, pointers, and unions) ever have a copy constructor or postblit constructor and thus hasComplexCopying is never true for them. It is particularly important to note that unions never have a copy constructor or postblit constructor, so if a struct contains a union which contains one or more members which have a copy constructor or postblit constructor, that struct will have to have a user-defined copy constructor or posthblit constructor which explicitly copies the correct member of the union if you don't want the current value of the union to simply be memcopied when copying the struct.
If a particular piece of code cares about the existence of a copy constructor or postblit constructor specifically rather than if a type has one or the other, the traits __traits(hasCopyConstructor, T) and __traits(hasPostblit, T) can be used, though note that they will not be true for static arrays.