July 10 [Issue 24657] New: 0-sized struct should be rejected in @safe mode | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24657 Issue ID: 24657 Summary: 0-sized struct should be rejected in @safe mode Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: bugzilla@digitalmars.com The following: struct S { } pragma(msg, s.sizeof); prints 1. But: extern (C) struct S { } pragma(msg, s.sizeof); prints 0. extern(C++) results in a size of 1. The size 1 comes from C++, which (correctly) decided that individual objects should have distinct addresses. This does have the potential to be memory unsafe, and a struct with no data members should be rejected in @safe mode. -- |
Copyright © 1999-2021 by the D Language Foundation