Bug 24220 – Static array of nested struct changes .init value at runtime

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-11-02T15:20:22Z
Last change time
2024-12-13T19:31:31Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#20350 →

Comments

Comment #0 by snarwin+bugzilla — 2023-11-02T15:20:22Z
As of DMD 2.105.3, the following program asserts at runtime: --- void main() { int n; struct Nested { int fun() { return n; } } static a = Nested.init; auto b = Nested.init; assert(a is b); // ok static a1 = (Nested[1]).init; auto b1 = (Nested[1]).init; assert(a1[0] is b1[0]); // fails } --- The error message, with -checkaction=context, is: --- [email protected](15): Nested(<context>: 0x0) !is Nested(<context>: 0x7f8e09158000) --- A variable initialized with Nested.init will always have a null context pointer, whether it is initialized at compile time or runtime. However, a variable initialized with (Nested[1]).init has a null context pointer when initialized at compile time, and a non-null context pointer when initialized at runtime. For the sake of consistency, the context pointer should be null in all cases.
Comment #1 by robert.schadek — 2024-12-13T19:31:31Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20350 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB