diff --git a/src/core/internal/traits.d b/src/core/internal/traits.d index 0662b457f3..d2dafb9145 100644 --- a/src/core/internal/traits.d +++ b/src/core/internal/traits.d @@ -292,7 +292,7 @@ template hasElaborateCopyConstructor(S) } else static if (is(S == struct)) { - enum hasElaborateCopyConstructor = __traits(hasMember, S, "__xpostblit"); + enum hasElaborateCopyConstructor = __traits(hasCopyConstructor, S) || __traits(hasPostblit, S); } else { @@ -300,6 +300,35 @@ template hasElaborateCopyConstructor(S) } } +@safe unittest +{ + static struct S + { + int x; + this(return scope ref typeof(this) rhs) { } + this(int x, int y) {} + } + + static assert(hasElaborateCopyConstructor!S); + + static struct S2 + { + int x; + this(int x, int y) {} + } + + static assert(!hasElaborateCopyConstructor!S2); + + static struct S3 + { + int x; + this(return scope ref typeof(this) rhs, int x = 42) { } + this(int x, int y) {} + } + + static assert(hasElaborateCopyConstructor!S3); +} + template hasElaborateAssign(S) { static if (__traits(isStaticArray, S) && S.length)