diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 614a29ec55..e1daf615fa 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -8978,6 +8978,7 @@ struct Id final static Identifier* getLocation; static Identifier* hasPostblit; static Identifier* hasCopyConstructor; + static Identifier* hasMoveConstructor; static Identifier* isCopyable; static Identifier* toType; static Identifier* parameters; diff --git a/compiler/src/dmd/id.d b/compiler/src/dmd/id.d index aae07bc153..ee4214a4c1 100644 --- a/compiler/src/dmd/id.d +++ b/compiler/src/dmd/id.d @@ -519,6 +519,7 @@ immutable Msgtable[] msgtable = { "getLocation" }, { "hasPostblit" }, { "hasCopyConstructor" }, + { "hasMoveConstructor" }, { "isCopyable" }, { "toType" }, { "parameters" }, diff --git a/compiler/src/dmd/traits.d b/compiler/src/dmd/traits.d index f7f4cd2bb5..34cdf816eb 100644 --- a/compiler/src/dmd/traits.d +++ b/compiler/src/dmd/traits.d @@ -544,7 +544,9 @@ Expression semanticTraits(TraitsExp e, Scope* sc) } return True(); } - if (e.ident == Id.hasCopyConstructor || e.ident == Id.hasPostblit) + if (e.ident == Id.hasCopyConstructor || + e.ident == Id.hasMoveConstructor || + e.ident == Id.hasPostblit) { if (dim != 1) return dimError(1); @@ -562,8 +564,14 @@ Expression semanticTraits(TraitsExp e, Scope* sc) auto ts = tb.isTypeStruct(); if (auto sd = ts ? ts.sym : null) { - return (e.ident == Id.hasPostblit) ? (sd.postblit ? True() : False()) - : (sd.hasCopyCtor ? True() : False()); + bool result; + if (e.ident == Id.hasPostblit) + result = sd.postblit !is null; + else if (e.ident == Id. hasCopyConstructor) + result = sd.hasCopyCtor; + else + result = sd.hasMoveCtor; + return result ? True() : False(); } return False(); } diff --git a/compiler/test/compilable/traits.d b/compiler/test/compilable/traits.d index d5e2cb0f22..09538b1dd4 100644 --- a/compiler/test/compilable/traits.d +++ b/compiler/test/compilable/traits.d @@ -137,6 +137,8 @@ struct DisabledPostblit struct NoCpCtor { } class C19902 { } +struct MoveCtor { this(MoveCtor) { } } + static assert(__traits(hasCopyConstructor, S)); static assert(__traits(hasCopyConstructor, OuterS.S)); static assert(__traits(hasCopyConstructor, OuterS)); @@ -147,6 +149,8 @@ static assert(__traits(hasCopyConstructor, U!S)); static assert(!__traits(hasPostblit, U!S)); static assert(__traits(hasPostblit, SPostblit)); static assert(!__traits(hasCopyConstructor, SPostblit)); +static assert(__traits(hasMoveConstructor, MoveCtor)); +static assert(!__traits(hasMoveConstructor, NoCpCtor)); static assert(!__traits(hasCopyConstructor, NoCpCtor)); static assert(!__traits(hasCopyConstructor, C19902));