Bug 7225 – immutable argument by const ref

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-01-04T14:15:00Z
Last change time
2013-01-16T07:06:19Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-01-04T14:15:07Z
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
Comment #1 by yebblies — 2013-01-16T07:06:19Z
*** This issue has been marked as a duplicate of issue 6708 ***