[Issue 24657] New: 0-sized struct should be rejected in @safe mode
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 10 19:02:04 UTC 2024
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 at puremagic.com
Reporter: bugzilla at 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.
--
More information about the Digitalmars-d-bugs
mailing list