File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -428,6 +428,7 @@ immutable Msgtable[] msgtable =
428
428
{ " isZeroInit" },
429
429
{ " getTargetInfo" },
430
430
{ " getLocation" },
431
+ { " hasElaborateCopyConstructor" },
431
432
432
433
// For C++ mangling
433
434
{ " allocator" },
Original file line number Diff line number Diff line change @@ -144,6 +144,7 @@ shared static this()
144
144
" isZeroInit" ,
145
145
" getTargetInfo" ,
146
146
" getLocation" ,
147
+ " hasElaborateCopyConstructor"
147
148
];
148
149
149
150
traitsStringTable._init(names.length);
@@ -596,7 +597,8 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
596
597
sm => sm.isTemplateDeclaration() ! is null ) != 0 ;
597
598
});
598
599
}
599
- if (e.ident == Id.isPOD)
600
+ if (e.ident == Id.isPOD ||
601
+ e.ident == Id.hasElaborateCopyConstructor)
600
602
{
601
603
if (dim != 1 )
602
604
return dimError (1 );
@@ -613,7 +615,14 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
613
615
Type tb = t.baseElemOf();
614
616
if (auto sd = tb.ty == Tstruct ? (cast (TypeStruct)tb).sym : null )
615
617
{
616
- return sd.isPOD() ? True() : False();
618
+ if (e.ident == Id.isPOD)
619
+ {
620
+ return sd.isPOD() ? True() : False();
621
+ }
622
+ else if (e.ident == Id.hasElaborateCopyConstructor)
623
+ {
624
+ return sd.hasCopyCtor ? True() : False();
625
+ }
617
626
}
618
627
return True ();
619
628
}
Original file line number Diff line number Diff line change @@ -86,3 +86,45 @@ struct Outer
86
86
static assert (__traits(getLocation, Outer.Nested)[1 ] == 82 );
87
87
static assert (__traits(getLocation, Outer.method)[1 ] == 84 );
88
88
89
+ /* *****************************************/
90
+ // https://issues.dlang.org/show_bug.cgi?id=19902
91
+ // Define hasElaborateCopyConstructor trait
92
+
93
+ struct S
94
+ {
95
+ this (ref S rhs) {}
96
+ }
97
+
98
+ struct OuterS
99
+ {
100
+ struct S
101
+ {
102
+ this (ref S rhs) {}
103
+ }
104
+ }
105
+
106
+ void foo (T)()
107
+ {
108
+ struct S (U)
109
+ {
110
+ this (ref S rhs) {}
111
+ }
112
+ static assert (__traits(hasElaborateCopyConstructor, S! int ));
113
+ }
114
+
115
+ struct U (T) {
116
+ this (ref U rhs) {}
117
+ }
118
+
119
+ struct SPostblit {
120
+ this (this ) {}
121
+ }
122
+
123
+ static assert (__traits(hasElaborateCopyConstructor, S));
124
+ static assert (__traits(hasElaborateCopyConstructor, OuterS.S));
125
+ static assert (__traits(compiles, foo! int ));
126
+ static assert (__traits(compiles, foo! S));
127
+ static assert (__traits(hasElaborateCopyConstructor, U! int ));
128
+ static assert (__traits(hasElaborateCopyConstructor, U! S));
129
+
130
+ static assert (! __traits(hasElaborateCopyConstructor, SPostblit));
You can’t perform that action at this time.
0 commit comments