-betterC and extern(C++) classes

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 10 06:19:13 PDT 2017

On Sunday, 10 September 2017 at 09:31:55 UTC, Walter Bright wrote:
> On 9/10/2017 1:40 AM, Yuxuan Shui wrote:
>> I was experimenting with -betterC and found out that C++ 
>> classes doesn't work. Because the resulting object file needs 
>> a symbol "_D14TypeInfo_Class6__vtblZ" which is in druntime. I 
>> suppose this is to support T.classinfo?
>> Could we remove T.classinfo and make classes work under 
>> -betterC? Or is there some other reason preventing this from 
>> happening?
> Yes, we do want to move towards "Better C++" working in an 
> analogous manner, and that means removing the typeinfo 
> dependency.

If TypeInfo for extern(C++) classes is removed, couldn't final 
extern(C++) classes without base class and which don't implement 
any interfaces omit the vtable so that the following assert holds:

final extern(C++) class Foo {}
static assert (__traits(classInstanceSize, Foo) == 0LU);

The reason I ask is that fairly often I have an abstraction 
that's better suited as a reference type than a value type, but 
doesn't need any runtime polymorphy (or the monitor standard 
classes have). Structs + pointers are the only way I know of to 
avoid the (in this special case) unneeded vtable overhead, but it 
always ends up looking worse to read.

More information about the Digitalmars-d mailing list