Bug 17822 – [betterC] Do not emit reference to TypeInfo_Class for C++ or COM classes

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-09-10T21:34:04Z
Last change time
2022-06-11T17:03:29Z
Keywords
betterC
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2017-09-10T21:34:04Z
The following code: extern (C++) class CC { int a; } when compiled with -betterC emits a reference to TypeInfo_Class, which is in druntime.
Comment #1 by dfj1esp02 — 2017-09-11T10:07:43Z
Isn't it needed for initializer? What's really not needed is registration in moduleinfo: C++ classes can't support Object.factory.
Comment #2 by alphaglosined — 2022-06-11T17:03:29Z
The definition by itself does not error. But it is possible to make it error with a ClassZ linker error if you use new. Works: ```d extern (C++) class CC { int a; } extern(C) void main() { __gshared CC cc = new CC; cc.a = 4; } ``` And so does: ```d extern (C++) class CC { int a; } extern(C) void main() { scope CC cc = new CC; cc.a = 4; } ``` Doesn't: ```d extern (C++) class CC { int a; } extern(C) void main() { CC cc = new CC; cc.a = 4; } ``` With: ``` ./onlineapp.d:6: error: undefined reference to '_D9onlineapp2CC7__ClassZ' ./onlineapp.d:6: error: undefined reference to '_d_newclass' collect2: error: ld returned 1 exit status ``` I'll close this as WORKSFORME, because it seems to be working correctly.