I was talking with some people about the current state about betterC classes. They said classes should work using both `emplace` and `scoped`. Some people said that D can't support vtable for betterC classes right now because of its ClassInfo. I don't really remember all the details, but it seems the problem is that TypeInfo and ClassInfo aren't separated, which D some long time ago actually separated for having .classInfo properties for classes. The decision for that was for more performance and optimization opportunities. However, this decision which was made much time before betterC was even thought made classes unusable in betterC mode. As it is possible to do that without garbage collection, I believe this is a fair enhancement, if at least separating the class info again for the betterC switch, which would be able to bring a lot of new opportunities.
Comment #1 by alphaglosined — 2022-03-18T01:09:14Z
Current status:
import core.lifetime;
extern(C) void main()
{
void[1000] buffer = void;
Foo foo = emplace!Foo(buffer[], 12);
}
class Foo {
this(int) {}
}
Output:
onlineapp.o:onlineapp.d:_D9onlineapp3Foo7__ClassZ: error: undefined reference to '_D14TypeInfo_Class6__vtblZ'
onlineapp.o:onlineapp.d:_D9onlineapp3Foo7__ClassZ: error: undefined reference to '_D6Object7__ClassZ'
onlineapp.o:onlineapp.d:_D9onlineapp3Foo6__vtblZ: error: undefined reference to '_D6object6Object8toStringMFZAya'
onlineapp.o:onlineapp.d:_D9onlineapp3Foo6__vtblZ: error: undefined reference to '_D6object6Object6toHashMFNbNeZm'
onlineapp.o:onlineapp.d:_D9onlineapp3Foo6__vtblZ: error: undefined reference to '_D6object6Object5opCmpMFCQqZi'
onlineapp.o:onlineapp.d:_D9onlineapp3Foo6__vtblZ: error: undefined reference to '_D6object6Object8opEqualsMFCQtZb'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
Comment #2 by moonlightsentinel — 2022-03-18T01:38:09Z
(In reply to Richard Cattermole from comment #1)
> Current status:
> [...]
N.B.: Currently works when explicitly passing libdruntime.a to the linker (-L-ldruntime)
Comment #3 by robert.schadek — 2024-12-13T19:21:30Z