Example:
int y;
class C { this(int x) { y = x; } }
import std.typecons: scoped;
scoped!C(1); // crashes, as ctx.y segfaults when ctx remains null
scoped should probably reject classes that have a "this" member (that aren't `static class`).
Comment #1 by simen.kjaras — 2018-07-30T19:36:58Z
This issue is also present in std.conv.emplace (which scoped uses internally).
At least currently, it is impossible to get a good value for the context pointer:
unittest {
int y;
class C { this(int x) { y = x; } }
create!C();
}
T create(T)() {
// outer function context of foo.__unittest_L1_C1 is
// needed to new nested class foo.__unittest_L1_C1.C
return new T(0);
}
emplace already checks for isInnerClass!T, and should also check for nested, non-inner classes. std.traits should have a trait that checks for this (hasContext? isNestedClass sounds like it should include isInnerClass).