Created attachment 1506
Minimal Code Sample
Calling ClassInfo.Create will fail for a class nested within a function. Minimal code to reproduce the issue follows:
[CODE]
extern (C) Object _d_newclass(const TypeInfo_Class ci);
void main()
{
int kittens;
class Foo {
this() { kittens = 1; }
~this() { kittens = 0; }
}
Foo f = new Foo(); // this works
typeid(f).create(); // fails
}
[/CODE]
Comment #1 by k.hara.pg — 2015-04-04T09:32:16Z
TypeInfo_Create.create() takes no parameter, so it cannot create nested classes with valid context pointer. Today it's filled by null, and any accesses to the enclosing context will cause Access Violation.
I'm not sure what's expected 'fix' for the issue. The class Foo is declared inside main(), so constructing Foo instance by using TypeInfo_Create.create() in main() is definitely redundant.
Are you requiring the create() call should throw a runtime exception for the impossible nested class construction?
Comment #2 by dlang-bugzilla — 2017-06-26T01:32:49Z
(In reply to Kenji Hara from comment #1)
> Are you requiring the create() call should throw a runtime exception for the
> impossible nested class construction?
Updated issue title accordingly.
Comment #3 by robert.schadek — 2024-12-07T13:35:06Z