Second Draft: Placement New Expression
Paul Backus
snarwin at gmail.com
Tue Nov 19 19:02:35 UTC 2024
On Tuesday, 19 November 2024 at 05:05:57 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> This still includes typed expressions, which I have some
> concerns about.
>
> We should not be condoning uninitialized memory as having a
> type. It can only cause problems for people. If we stick to
> ``void[]`` as the input, we can limit the source to ``@system``
> code only.
>
> No double-init bugs please.
+1
Using a typed lvalue instead of void[] is just asking to shoot
yourself in the foot, especially when it comes to const/immutable:
struct S { int i; char c; }
void main()
{
S dest;
immutable(S)* p = new immutable(S)(dest)(123, 'A');
assert(p.i == 123 && p.c == 'A');
dest.i = 0; // oops, undefined behavior!
}
More information about the dip.development
mailing list