February 07, 2020 [Issue 20564] New: Member function increases struct size when the struct is defined in a function | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20564 Issue ID: 20564 Summary: Member function increases struct size when the struct is defined in a function Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: regression Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: kiithsacmp@gmail.com Adding a method to a struct definition in a function increases the struct size. Build this code to reproduce: ``` void fun() { struct InnerFun { ubyte a; void fun() {} } struct InnerNoFun { ubyte a; } // prints 16, expected 1 pragma(msg, "InnerFun ", InnerFun.sizeof); // prints 1 pragma(msg, "InnerNoFun ", InnerNoFun.sizeof); } struct OuterFun { ubyte a; void fun() {} } struct OuterNoFun { ubyte a; } // prints 1 pragma(msg, "OuterFun ", OuterFun.sizeof); // prints 1 pragma(msg, "OuterNoFun ", OuterNoFun.sizeof); void main(){} ``` Actual results: ``` OuterFun 1LU OuterNoFun 1LU InnerFun 16LU InnerNoFun 1LU ``` Expected results: ``` OuterFun 1LU OuterNoFun 1LU InnerFun 1LU InnerNoFun 1LU ``` Reproduced on DMD 2.090, DMD 2.086, LDC 1.8.0 (based on DMD 2.078.3) on Ubuntu 18.04 Discovered while trying out `std.bitmanip.bitfields!()` in a unittest, where generated methods broke the test. -- |
Copyright © 1999-2021 by the D Language Foundation