[core.reflect] Detect Padding in structs or classes

Stefan Koch uplink.coder at googlemail.com
Fri Oct 1 19:25:36 UTC 2021

On Friday, 1 October 2021 at 18:30:35 UTC, Stefan Koch wrote:
> On Friday, 1 October 2021 at 17:35:24 UTC, Stefan Koch wrote:
>> There has been a PR to introduce `-vpadding` into dmd which 
>> warns on padding in structs.
>> This can actually be trivially done by core reflect.
> Ah dang.
> This code will be bogus for classes as we need it iterate the 
> base classes for this
> Which we can do but not when visiting the superclass of both 
> Struct and Class Declarations.
> We need to specialize for classes.
> And add the following code to the visitor
> ```D
>             override void visit(ClassDeclaration cd)
>             {
>                 ulong lastOffset;
> ```
Ah double dang.
This code needs to be fixed.
For classes we start at offset 16 because of class-metadata like 
the vtbl and monitor being prepended. So it should read
`ulong lastOffset = 16`

More information about the Digitalmars-d mailing list