Bug 11743 – cannot initialize const arrays with out parameters

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-14T11:08:45Z
Last change time
2024-12-13T18:15:13Z
Assigned to
No Owner
Creator
Walter Bright
Moved to GitHub: dmd#18739 →

Comments

Comment #0 by bugzilla — 2013-12-14T11:08:45Z
The following shows the problem: --------------------- struct S { const int[] x; const int[] y; const int z; this(int i) { x = null; // works foo(y); // fails bar(z); // works } } void foo(out int[] y) { y = null; } void bar(out int z) { z = 1; } --------------------- dmd -c foo foo.d(9): Error: function foo.foo (out int[] y) is not callable using argument types (const(int[]))
Comment #1 by k.hara.pg — 2013-12-14T22:00:57Z
(In reply to comment #0) > The following shows the problem: > --------------------- > struct S { > const int[] x; > const int[] y; > const int z; > > this(int i) { > x = null; // works > foo(y); // fails > bar(z); // works > } > } > > void foo(out int[] y) { y = null; } > > void bar(out int z) { z = 1; } > --------------------- I think bar(z); should also be rejected, because it would violate const system. struct S { immutable int z; this(int i) { bar(z); // works } } int* g; void bar(out int z) { z = 1; g = &z; } void main() { S s = S(1); assert(s.z == 1 && is(typeof(s.z) == immutable int)); *g = 100; assert(s.z == 1); // fails! }
Comment #2 by robert.schadek — 2024-12-13T18:15:13Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18739 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB