Summary: immutable ref implicit cast to const ref
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-09-21 13:48:10 PDT ---
I think this is correct code because foo and bar can't change the contents of
arr and x in any way:

void foo(const ref int y) {}
void bar(const ref int[5] a1) {}
void spam(const ref int[] a2) {}
void baz(const ref int[int] aa) {}
void main() {
    immutable int x;
    foo(x); // Error?
    immutable int[5] arr1;
    bar(arr1); // Error?
    immutable int[] arr2;
    spam(arr2); // Error?
    immutable int[int] aa;
    baz(aa); // Error?

But DMD 2.055 gives errors:

test.d(7): Error: constant 0 is not an lvalue
test.d(9): Error: cast(const(int[5u]))arr1 is not an lvalue
test.d(11): Error: cast(const(int[]))arr2 is not an lvalue
test.d(13): Error: cast(const(int[int]))aa is not an lvalue

See also a thread on this topic in D.learn:

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to