fix #21203 Placement new does not count as initialization (#21243)

This commit is contained in:
Walter Bright 2025-04-16 00:14:46 -07:00 committed by GitHub
parent 1244ef260b
commit d6602a6b0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 11 deletions

View file

@ -106,6 +106,32 @@ void test7()
assert(t.x == 10 && t.y == 20);
}
/*************************************************/
// https://github.com/dlang/dmd/issues/21203
struct Y8
{
int a;
this() @disable; // default disabled
this(int i) { a = i; }
}
struct S8
{
Y8 m;
this(int x)
{
new(m) Y8(x); // initialise `m`
}
}
void test8()
{
S8 s = S8(3);
assert(s.m.a == 3);
}
/*************************************************/
int main()
@ -117,6 +143,7 @@ int main()
test5();
test6();
test7();
test8();
return 0;
}