Bug 24657 – 0-sized struct should be rejected in @safe mode

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-07-10T19:02:04Z
Last change time
2024-12-13T19:36:24Z
Keywords
safe
Assigned to
No Owner
Creator
Walter Bright
Moved to GitHub: dmd#18256 →

Comments

Comment #0 by bugzilla — 2024-07-10T19:02:04Z
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.
Comment #1 by elpenguino+D — 2024-07-10T19:12:53Z
How could this result in memory corruption?
Comment #2 by robert.schadek — 2024-12-13T19:36:24Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18256 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB