On Friday, 8 April 2022 at 09:08:07 UTC, Stanislav Blinov wrote:
On Friday, 8 April 2022 at 05:53:03 UTC, Elvis Zhou wrote:
assumeNoEscapeOrWhatever!DynamicArray structs;
structs ~= cast(A*)&b;
is it possible?
That's what `@trusted` is for. And that's also why it should be
used with care, a
On Friday, 8 April 2022 at 05:46:56 UTC, Elvis Zhou wrote:
On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote:
[...]
I know where the issue comes from, dynamic array is GCed and
save the reference of a local variable in GCed memory is not
allowed, but here structs is assumed to not es
On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote:
struct A {}
struct B { A a; }
struct C { A a; }
A*[] structs;
B b;
init(&b);
structs ~= cast(A*)&b;
//Error: copying `cast(A*)& b` into allocated memory escapes a
reference to local variable `b`
C c;
init(&c);
structs ~= cast(A*)&c;
struct A {}
struct B { A a; }
struct C { A a; }
A*[] structs;
B b;
init(&b);
structs ~= cast(A*)&b;
//Error: copying `cast(A*)& b` into allocated memory escapes a
reference to local variable `b`
C c;
init(&c);
structs ~= cast(A*)&c;
//Error: copying `cast(A*)& c` into allocated memory escap