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

Commit a87fe49

Browse files
committed
Fix Issue 19401 - Fix hasElaborateDestructor & hasElaborateCopyConstructor for struct with static array alias & for nested structs/unions
1 parent 1b106de commit a87fe49

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/core/internal/traits.d

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,46 +163,50 @@ template anySatisfy(alias F, T...)
163163
}
164164
}
165165

166-
// Somehow fails for non-static nested structs without support for aliases
167-
template hasElaborateDestructor(T...)
166+
// std.traits.Fields
167+
private template Fields(T)
168168
{
169-
static if (is(T[0]))
170-
alias S = T[0];
169+
static if (is(T == struct) || is(T == union))
170+
alias Fields = typeof(T.tupleof[0 .. $ - __traits(isNested, T)]);
171+
else static if (is(T == class))
172+
alias Fields = typeof(T.tupleof);
171173
else
172-
alias S = typeof(T[0]);
174+
alias Fields = TypeTuple!T;
175+
}
173176

174-
static if (is(S : E[n], E, size_t n) && S.length)
177+
// std.traits.hasElaborateDestructor
178+
template hasElaborateDestructor(S)
179+
{
180+
static if (__traits(isStaticArray, S) && S.length)
175181
{
176-
enum bool hasElaborateDestructor = hasElaborateDestructor!E;
182+
enum bool hasElaborateDestructor = hasElaborateDestructor!(typeof(S.init[0]));
177183
}
178184
else static if (is(S == struct))
179185
{
180186
enum hasElaborateDestructor = __traits(hasMember, S, "__dtor")
181-
|| anySatisfy!(.hasElaborateDestructor, S.tupleof);
187+
|| anySatisfy!(.hasElaborateDestructor, Fields!S);
182188
}
183189
else
190+
{
184191
enum bool hasElaborateDestructor = false;
192+
}
185193
}
186194

187-
// Somehow fails for non-static nested structs without support for aliases
188-
template hasElaborateCopyConstructor(T...)
195+
// std.traits.hasElaborateCopyDestructor
196+
template hasElaborateCopyConstructor(S)
189197
{
190-
static if (is(T[0]))
191-
alias S = T[0];
192-
else
193-
alias S = typeof(T[0]);
194-
195-
static if (is(S : E[n], E, size_t n) && S.length)
198+
static if (__traits(isStaticArray, S) && S.length)
196199
{
197-
enum bool hasElaborateCopyConstructor = hasElaborateCopyConstructor!E;
200+
enum bool hasElaborateCopyConstructor = hasElaborateCopyConstructor!(typeof(S.init[0]));
198201
}
199202
else static if (is(S == struct))
200203
{
201-
enum hasElaborateCopyConstructor = __traits(hasMember, S, "__postblit")
202-
|| anySatisfy!(.hasElaborateCopyConstructor, S.tupleof);
204+
enum hasElaborateCopyConstructor = __traits(hasMember, S, "__xpostblit");
203205
}
204206
else
207+
{
205208
enum bool hasElaborateCopyConstructor = false;
209+
}
206210
}
207211

208212
// std.meta.Filter

0 commit comments

Comments
 (0)