Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 0c3fd57

Browse files
committed
Fix issue 19902 - hasElaborateCopyConstructor doesn't know about copy constructors
1 parent c66ae59 commit 0c3fd57

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/core/internal/traits.d

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,43 @@ template hasElaborateCopyConstructor(S)
292292
}
293293
else static if (is(S == struct))
294294
{
295-
enum hasElaborateCopyConstructor = __traits(hasMember, S, "__xpostblit");
295+
enum hasElaborateCopyConstructor = __traits(hasCopyConstructor, S) || __traits(hasPostblit, S);
296296
}
297297
else
298298
{
299299
enum bool hasElaborateCopyConstructor = false;
300300
}
301301
}
302302

303+
@safe unittest
304+
{
305+
static struct S
306+
{
307+
int x;
308+
this(return scope ref typeof(this) rhs) { }
309+
this(int x, int y) {}
310+
}
311+
312+
static assert(hasElaborateCopyConstructor!S);
313+
314+
static struct S2
315+
{
316+
int x;
317+
this(int x, int y) {}
318+
}
319+
320+
static assert(!hasElaborateCopyConstructor!S2);
321+
322+
static struct S3
323+
{
324+
int x;
325+
this(return scope ref typeof(this) rhs, int x = 42) { }
326+
this(int x, int y) {}
327+
}
328+
329+
static assert(hasElaborateCopyConstructor!S3);
330+
}
331+
303332
template hasElaborateAssign(S)
304333
{
305334
static if (__traits(isStaticArray, S) && S.length)

0 commit comments

Comments
 (0)