Skip to content

Commit

Permalink
Postblit is still a form of copy constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
edi33416 committed Aug 2, 2019
1 parent 011b7c6 commit a17241e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/dmd/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
}
else if (e.ident == Id.hasElaborateCopyConstructor)
{
return sd.hasCopyCtor ? True() : False();
return sd.hasCopyCtor || sd.postblit !is null ? True() : False();
}
}
return True();
Expand Down
11 changes: 8 additions & 3 deletions test/compilable/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,24 @@ void foo(T)()
static assert (__traits(hasElaborateCopyConstructor, S!int));
}

struct U(T) {
struct U(T)
{
this (ref U rhs) {}
}

struct SPostblit {
struct SPostblit
{
this(this) {}
}

struct NoCpCtor { }

static assert(__traits(hasElaborateCopyConstructor, S));
static assert(__traits(hasElaborateCopyConstructor, OuterS.S));
static assert(__traits(compiles, foo!int));
static assert(__traits(compiles, foo!S));
static assert(__traits(hasElaborateCopyConstructor, U!int));
static assert(__traits(hasElaborateCopyConstructor, U!S));
static assert(__traits(hasElaborateCopyConstructor, SPostblit));

static assert(!__traits(hasElaborateCopyConstructor, SPostblit));
static assert(!__traits(hasElaborateCopyConstructor, NoCpCtor));

0 comments on commit a17241e

Please sign in to comment.