[Issue 11743] cannot initialize const arrays with out parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 14 22:00:58 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11743



--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2013-12-14 22:00:57 PST ---
(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!
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list