D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11743 - cannot initialize const arrays with out parameters
Summary: cannot initialize const arrays with out parameters
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-14 11:08 UTC by Walter Bright
Modified: 2024-12-13 18:15 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2013-12-14 11:08:45 UTC
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 Kenji Hara 2013-12-14 22:00:57 UTC
(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 dlangBugzillaToGithub 2024-12-13 18:15:13 UTC
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