[Issue 7225] New: immutable argument by const ref

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 4 14:15:10 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7225

           Summary: immutable argument by const ref
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-01-04 14:15:07 PST ---
In this program:
- a1 gives no errors and this is correct;
- a2 gives an error, and I think this is correct;
- a3 too gives an error, and I think this is not correct, because it not a
manifest constant:


void foo(const ref int[2] M) {}
void main() {
    const int[2] a1 = [1, 2];
    foo(a1);
    enum int[2] a2 = [1, 2]; // line 5
    foo(a2);
    immutable int[2] a3 = [1, 2];
    foo(a3);
}


DMD 2.058head gives:

test.d(6): Error: function test.foo (ref const(int[2u]) M) is not callable
using argument types (int[2u])
test.d(5): Error: [1,2] is not an lvalue
test.d(8): Error: cast(const(int[2u]))a3 is not an lvalue

The first two error messages are not good, I think they should be merged in a
single more clear error message relative to just line 6.


A similar program that uses just ints:

void foo(const ref int M) {}
void main() {
    const int a1 = 1;
    foo(a1);
    enum int a2 = 1;
    foo(a2);
    immutable int a3 = 1;
    foo(a3);
}


DMD 2.058head gives:

test.d(6): Error: function test3.foo (ref const(int) M) is not callable using
argument types (int)
test.d(5): Error: constant 1 is not an lvalue
test.d(8): Error: constant 1 is not an lvalue

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


More information about the Digitalmars-d-bugs mailing list