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

Commit 329f763

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

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/core/internal/traits.d

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,39 @@ template hasElaborateCopyConstructor(S)
290290
{
291291
enum bool hasElaborateCopyConstructor = hasElaborateCopyConstructor!(typeof(S.init[0]));
292292
}
293-
else static if (is(S == struct))
293+
else
294294
{
295-
enum hasElaborateCopyConstructor = __traits(hasMember, S, "__xpostblit");
295+
enum bool hasElaborateCopyConstructor = __traits(hasCopyConstructor, S) || __traits(hasPostblit, S);
296296
}
297-
else
297+
}
298+
299+
@safe unittest
300+
{
301+
static struct S
302+
{
303+
int x;
304+
this(return scope ref typeof(this) rhs) { }
305+
this(int x, int y) {}
306+
}
307+
308+
static assert(hasElaborateCopyConstructor!S);
309+
310+
static struct S2
311+
{
312+
int x;
313+
this(int x, int y) {}
314+
}
315+
316+
static assert(!hasElaborateCopyConstructor!S2);
317+
318+
static struct S3
298319
{
299-
enum bool hasElaborateCopyConstructor = false;
320+
int x;
321+
this(return scope ref typeof(this) rhs, int x = 42) { }
322+
this(int x, int y) {}
300323
}
324+
325+
static assert(hasElaborateCopyConstructor!S3);
301326
}
302327

303328
template hasElaborateAssign(S)

0 commit comments

Comments
 (0)